﻿using Abp.Domain.Repositories;
using Camc.Quality.Bop.Dto;
using Camc.Quality.Bop.TreeObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Abp.UI;
using Camc.Quality.Quality;
using Camc.Quality.Dto.TechniqueEntityDto;
using Camc.Quality.Dto.ProcessesEntityDto;
using System.IO;
using Camc.Quality.Bop.QualityDto;
using Camc.Quality.Dto.TableOutDto;
using Camc.Quality.RecordTable.FormClass;
using Camc.Quality.Authorization.Users;
using Camc.Quality.Authorization.Roles;
using Abp.Authorization.Users;
using Camc.Quality.Dto;
using Camc.Quality.Dto.TableDto;
using Camc.Quality.Dto.TableDto.BopDto;
using Abp.Domain.Uow;
using System.IO.Compression;
using Camc.Quality.FilesTransfer;
using Camc.Quality.Dto.TableDto.BopDto.Substance;
using Camc.Quality.Bop.IbopInterface;
using Camc.Quality.RecordTable.FormBase;
using Camc.Quality.DataDictionary;
using Camc.Quality.IOperationHistory;
using Abp.Runtime.Validation;
using Microsoft.AspNetCore.Http;
using Camc.Quality.Bop.UnifyDto;
using Microsoft.EntityFrameworkCore;
using Camc.Quality.StoreManagement.StoragePut;
using Camc.Quality.ProcessRoute;
using Camc.Quality.ProductionPlan;
using Camc.Quality.Storage;
using Abp.EntityFrameworkCore.Repositories;
using Abp.AspNetZeroCore.Net;
using Camc.Quality.Common;
using Abp.Extensions;
using System.Text.RegularExpressions;
using Abp.Organizations;
using System.Security.Cryptography;
using System.Text;
using Camc.Quality.Quality.TransformHtml;
using Newtonsoft.Json;
using EFCore.BulkExtensions;
using Camc.Quality.Dto.TableReturnDto.Technique;

namespace Camc.Quality.Bop
{

    public class BopNodeAppService : QualityAppServiceBase, IBopNodeAppService
    {


        public int NodeLevel = 2;
        public int PreNodeLevel;
        private readonly IRepository<Role> _roleRepository;
        private readonly IRepository<User, long> _userRepository;
        private readonly RoleManager _roleManager;
        private readonly IRepository<UserRole, long> _userRoleRepository;
        private readonly IRepository<BopNode, Guid> _bopNodeRepository;
        private readonly IRepository<BopDesc, Guid> _bopDescRepository;
        private readonly IRepository<BopContent, Guid> _bopContentRepository;
        private readonly IRepository<TechniqueEntity, Guid> _techniqueEntityRepository;
        private readonly IRepository<ProcessesEntity, Guid> _processesEntityRepository;
        private readonly IRepository<WorkStepEntity, Guid> _workStepEntityRepository;
        private readonly IRepository<RbopDesc, Guid> _rBopDescRepository;
        private readonly IRepository<RbopNode, Guid> _rBopNodeRepository;
        private readonly IRepository<RbopContent, Guid> _rbopContentRepository;
        private readonly IRepository<TableBase, Guid> _tableBaseEntity;
        private readonly IRepository<MakeResourcesEntity, Guid> _makeResourcesEntityRepository;
        private readonly IRepository<MultiMediaEntity, Guid> _multiMediaRepository;
        private readonly IRepository<LoadPieceEntity, Guid> _loadPieceRepository;
        private readonly IRepository<ResourcesEntity, Guid> _resourcesEntityRepository;
        private readonly IRepository<TransducerConverter, Guid> _transducerConverteritory;
        private readonly IRepository<VideoEntity, Guid> _videoEntityRepository;
        private readonly IRepository<FileTransfer, Guid> _operationHeartBeat;
        private readonly IRepository<Sys_UserManage, long> _sys_UserManageRepository;
        private readonly IOperationHistoryAppService _iOperationHistoryAppService;
        public readonly IRepository<StoreStockContent, Guid> _storeStockContentRepsitory;
        private readonly IRepository<ProcessLine, Guid> _processLineRepository;
        private readonly IRepository<ProductionScheduler, Guid> _productionSchedulerRepository;
        private readonly ITempFileCacheManager _tempFileCacheManager;
        private readonly IRepository<TreeVersionLog, int> _treeVersionLogRepository;
        public readonly IRepository<StorePutContent, Guid> _storePutContentRepsitory;
        private readonly IRepository<UserOrganizationUnit, long> _userOrganizationUnitRepository;
        private readonly IRepository<OrganizationUnit, long> _organizationUnitRepository;
        private readonly IRepository<Sys_Code, Guid> _sysCodeRepository;
        private readonly IRepository<ConvertFormBase, Guid> _convertFormBaseEntity;
        private readonly IUnitOfWorkManager _unitOfWorkManager;
        public BopNodeAppService(
            IUnitOfWorkManager unitOfWorkManager,
            IOperationHistoryAppService iOperationHistoryAppService,
            IRepository<BopNode, Guid> bopNodeRepository,
            IRepository<TableBase, Guid> tableBaseEntity,
            IRepository<BopDesc, Guid> bopDescRepository,
            IRepository<BopContent, Guid> bopContentRepository,
            IRepository<RbopDesc, Guid> rBopDescRepository,
            IRepository<RbopNode, Guid> rBopNodeRepository,
            IRepository<RbopContent, Guid> rbopContentRepository,
            IRepository<TechniqueEntity, Guid> techniqueEntityRepository,
            IRepository<ProcessesEntity, Guid> processesEntityRepository,
            IRepository<WorkStepEntity, Guid> workStepEntityRepository,
            IRepository<MakeResourcesEntity, Guid> makeResourcesEntityRepository,
            IRepository<MultiMediaEntity, Guid> multiMediaRepository,
            IRepository<LoadPieceEntity, Guid> loadPieceRepository,
            IRepository<ResourcesEntity, Guid> resourcesEntityRepository,
            IRepository<TransducerConverter, Guid> transducerConverteritory,
            IRepository<User, long> userRepository,
            IRepository<UserRole, long> UserRoleRepository,
            RoleManager roleManager, IRepository<Role> RoleRepository,
            IRepository<VideoEntity, Guid> videoEntityRepository,
            IRepository<Sys_UserManage, long> sys_UserManageRepository,
            IRepository<StoreStockContent, Guid> storeStockContentRepsitory,
            IRepository<ProcessLine, Guid> processLineRepository,
            IRepository<ProductionScheduler, Guid> productionSchedulerRepository, ITempFileCacheManager tempFileCacheManager,
            IRepository<TreeVersionLog, int> treeVersionLogRepository,
            IRepository<StorePutContent, Guid> storePutContentRepsitory,
            IRepository<UserOrganizationUnit, long> userOrganizationUnitRepository,
            IRepository<OrganizationUnit, long> organizationUnitRepository,
            IRepository<Sys_Code, Guid> sysCodeRepository,
            IRepository<ConvertFormBase, Guid> convertFormBaseEntity)
        {
            _unitOfWorkManager = unitOfWorkManager;
            _iOperationHistoryAppService = iOperationHistoryAppService;
            _tableBaseEntity = tableBaseEntity;
            _bopNodeRepository = bopNodeRepository;
            _bopDescRepository = bopDescRepository;
            _rBopDescRepository = rBopDescRepository;
            _rBopNodeRepository = rBopNodeRepository;
            _rbopContentRepository = rbopContentRepository;
            _bopContentRepository = bopContentRepository;
            _techniqueEntityRepository = techniqueEntityRepository;
            _processesEntityRepository = processesEntityRepository;
            _workStepEntityRepository = workStepEntityRepository;
            _multiMediaRepository = multiMediaRepository;
            _loadPieceRepository = loadPieceRepository;
            _resourcesEntityRepository = resourcesEntityRepository;
            _transducerConverteritory = transducerConverteritory;
            _videoEntityRepository = videoEntityRepository;
            _userRepository = userRepository;
            _userRoleRepository = UserRoleRepository;
            _roleManager = roleManager;
            _roleRepository = RoleRepository;
            _makeResourcesEntityRepository = makeResourcesEntityRepository;
            _sys_UserManageRepository = sys_UserManageRepository;
            _storeStockContentRepsitory = storeStockContentRepsitory;
            _processLineRepository = processLineRepository;
            _productionSchedulerRepository = productionSchedulerRepository;
            _tempFileCacheManager = tempFileCacheManager;
            _treeVersionLogRepository = treeVersionLogRepository;
            _storePutContentRepsitory = storePutContentRepsitory;
            _userOrganizationUnitRepository = userOrganizationUnitRepository;
            _organizationUnitRepository = organizationUnitRepository;
            _sysCodeRepository = sysCodeRepository;
            _convertFormBaseEntity = convertFormBaseEntity;
        }
        /// <summary>
        /// Bop节点新增和修改接口，根据是否传输id判断（只针对2,、3、4）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ResultMessage> CreateOrUpdateBopNode(CreateOrUpdateBopNodeInput input)
        {
            ResultMessage resultMessage = new ResultMessage();
            if (string.IsNullOrWhiteSpace(input.BopNode.NodeDrawingNo))
            {
                resultMessage.code = 1;
                resultMessage.Message = "图号格式不正确!";
                return resultMessage;
                //throw new UserFriendlyException("图号格式不正确!");
            }
            if (string.IsNullOrWhiteSpace(input.BopNode.NodeName))
            {
                resultMessage.code = 1;
                resultMessage.Message = "名称格式不正确!";
                return resultMessage;
                //throw new UserFriendlyException("名称格式不正确!");
            }
            if (input.BopNode.Id == Guid.Empty)
            {
                resultMessage = await CreateBopNode(input);
            }
            else
            {
                resultMessage = await UpdateBopNode(input);
            }
            return resultMessage;
        }
        /// <summary>
        /// Bop节点 更新方法
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private async Task<ResultMessage> UpdateBopNode(CreateOrUpdateBopNodeInput input)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                var bop = await _bopNodeRepository.FirstOrDefaultAsync(c => c.Id == input.BopNode.Id);
                //var bopNew = ObjectMapper.Map(input.BopNode, bop);
                bop.NodeName = input.BopNode.NodeName;
                bop.NodeDrawingNo = input.BopNode.NodeDrawingNo;
                await _bopNodeRepository.UpdateAsync(bop);
                _iOperationHistoryAppService.InsertOperationLog(bop.BopDescId, 0, 7, "修改" + bop.NodeName + "节点");
                resultMessage.code = 0;
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }
        /// <summary>
        /// Bop节点 Insert
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private async Task<ResultMessage> CreateBopNode(CreateOrUpdateBopNodeInput input)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                //var releaseUserId = AbpSession.UserId;
                //查询父级节点信息
                var bopParent = await _bopNodeRepository.FirstOrDefaultAsync(c => c.Id == input.BopNode.ParentId);
                int lox = 0;
                int nodeLevel = 0;
                //父节点和子节点Code
                string parentCode = string.Empty;
                string nodeCode = string.Empty;
                Guid guid = Guid.NewGuid();

                double x = 0;
                double y = 0; //工艺路线坐标
                if (bopParent != null) //父节点不为null
                {
                    string processCode = bopParent.ProcessCode;
                    //防错：已关联工艺文件的节点不能增加子节点
                    if (string.IsNullOrEmpty(processCode))
                    {
                        //逻辑2，父级节点的改为非叶节点
                        bopParent.IsLeaf = 0;
                        await _bopNodeRepository.UpdateAsync(bopParent);
                        //取层级和父节点Code
                        nodeLevel = bopParent.NodeLevel;
                        if (nodeLevel == 3)
                        {
                            resultMessage.code = 1;
                            resultMessage.Message = "不能建立节点，节点最多4层级";
                            return resultMessage;
                            //throw new UserFriendlyException("不能建立节点，节点最多4层级");
                        }
                        parentCode = bopParent.NodeCode;
                        //取值父节点下子节点数量
                        using (UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
                        {
                            int i = await _bopNodeRepository.CountAsync(c => c.BopDescId == input.BopNode.BopDescId && c.ParentCode == parentCode);
                            i++;
                            lox = i;
                            nodeCode = parentCode + "-" + i.ToString().PadLeft(3, '0');
                        }
                    }
                    else
                    {
                        resultMessage.code = 1;
                        resultMessage.Message = "已关联工艺文件，不能增加子节点";
                        return resultMessage;
                        //throw new UserFriendlyException("已关联工艺文件，不能增加子节点");
                    }
                }
                else
                {
                    parentCode = "root";
                    using (UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
                    {
                        int i = await _bopNodeRepository.CountAsync(c => c.BopDescId == input.BopNode.BopDescId);
                        i++;
                        lox = i;
                        nodeCode = i.ToString().PadLeft(3, '0');
                    }
                }
                //获取兄弟节点数量
                var sbliNode = _bopNodeRepository.GetAll().Where(d => d.ParentId == input.BopNode.ParentId).ToList();
                if (sbliNode.Count > 0)
                {
                    //兄弟节点数量大于0 则 根据创建时间获取最后一个 节点 然后根据工艺路线获取 该节点的坐标 保持纵坐标不变 向左推迟300 个像素
                    var lastNode = sbliNode.OrderBy(d => d.CreationTime).Last();
                    var proLine = _processLineRepository.GetAll().Where(d => d.PPtr == input.BopNode.ParentId).Where(d => d.From == lastNode.Id).FirstOrDefault();
                    if (proLine != null)
                    {
                        if (!string.IsNullOrEmpty(lastNode.Loc))
                        {
                            var locArray = lastNode.Loc.Split(' '); //坐标存储 X,Y 先拆分 然后 X推迟300个单位
                            if (locArray.Length == 2)
                            {
                                x = Convert.ToDouble(locArray[0]) - 300;
                                y = Convert.ToDouble(locArray[1]);
                            }
                        }
                        proLine.To = guid;
                        await _processLineRepository.UpdateAsync(proLine);
                    }
                    else
                    {
                        //没有路线信息， 则默认最后一个节点 向左推迟300 个像素
                        if (!string.IsNullOrEmpty(lastNode.Loc))
                        {
                            var locArray = lastNode.Loc.Split(' ');
                            if (locArray.Length == 2)
                            {
                                x = Convert.ToDouble(locArray[0]) - 300;
                                y = Convert.ToDouble(locArray[1]);
                            }
                        }
                        ProcessLine processLine1 = new ProcessLine();
                        processLine1.PPtr = input.BopNode.ParentId;
                        processLine1.From = lastNode.Id;
                        processLine1.To = guid;
                        processLine1.BopDescId = input.BopNode.BopDescId;
                        await _processLineRepository.InsertAsync(processLine1);
                    }
                }
                else
                {
                    //没有兄弟节点 则以自身父亲节点 推迟 向上 推迟250单位 向右 推迟 1400  默认 从右往网做排列
                    if (bopParent != null)
                    {
                        if (!string.IsNullOrEmpty(bopParent.Loc))
                        {
                            var locArray = bopParent.Loc.Split(' ');
                            if (locArray.Length == 2)
                            {
                                x = Convert.ToDouble(locArray[0]) + 1400;
                                y = Convert.ToDouble(locArray[1]) - 250;
                            }
                        }
                    }
                    else
                    {
                        y = -250;
                    }

                }
                //更新路线信息
                ProcessLine processLine = new ProcessLine();
                processLine.PPtr = input.BopNode.ParentId;
                processLine.From = guid;
                processLine.To = input.BopNode.ParentId;
                processLine.BopDescId = input.BopNode.BopDescId;
                await _processLineRepository.InsertAsync(processLine);


                var bop = new BopNode()
                {
                    Id = guid,
                    ParentId = input.BopNode.ParentId,
                    BopDescId = input.BopNode.BopDescId,
                    NodeDrawingNo = input.BopNode.NodeDrawingNo,
                    NodeName = input.BopNode.NodeName,
                    NodeType = (NodeType)(input.BopNode.NodeType),
                    //逻辑1，新增的都是叶节点
                    IsLeaf = 1,
                    //逻辑3，增加层级NodeLevel的保存，原理，父级层级加1
                    NodeLevel = nodeLevel + 1,
                    ParentCode = parentCode,
                    NodeCode = nodeCode,
                    Loc = x.ToString() + " " + y.ToString(),
                    Figure = "RoundedRectangle",
                    Color = "black",
                    Size = 0,
                    Fill = "lightgray",
                };
                await _bopNodeRepository.InsertAsync(bop);
                _iOperationHistoryAppService.InsertOperationLog(bop.BopDescId, 0, 6, "创建" + bop.NodeName + "节点");
                resultMessage.code = 0;
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }
        /// <summary>
        ///根据节点Id查询节点信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<BopNodeDto> GetBopNodeById(Guid id)
        {
            var bomNode = await _bopNodeRepository.FirstOrDefaultAsync(x => x.Id == id);

            if (bomNode != null)
            {
                var bopNodeDto = ObjectMapper.Map<BopNodeDto>(bomNode);
                return bopNodeDto;
            }
            else
            {
                return new BopNodeDto();
            }
        }
        /// <summary>
        /// Bop节点 Delete
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task DeleteBopNode(Guid id)
        {
            var bopNode = _bopNodeRepository.FirstOrDefaultAsync(b => b.Id == id).Result;
            if (bopNode != null)
            {
                //删除逻辑：
                //当前节点和子节点有绑定文件的不能删除
                if (string.IsNullOrEmpty(bopNode.ProcessCode))
                {
                    int j = await _bopNodeRepository.CountAsync(c => c.BopDescId == bopNode.BopDescId && c.ParentCode.StartsWith(bopNode.NodeCode) && c.ProcessCode != null);
                    if (j == 0)
                    {
                        //1、需要修改父级是否是叶节点数据
                        int i = await _bopNodeRepository.CountAsync(c => c.BopDescId == bopNode.BopDescId && c.ParentCode == bopNode.ParentCode && c.Id != bopNode.Id);
                        if (i == 0)
                        {
                            //修改父节点为叶节点
                            var bop = await _bopNodeRepository.FirstOrDefaultAsync(c => c.Id == bopNode.ParentId);
                            if (bop != null)
                            {
                                bop.IsLeaf = 1;
                                await _bopNodeRepository.UpdateAsync(bop);
                            }
                        }
                        //2、删除所有父节点是该节点的数据
                        await _bopNodeRepository.DeleteAsync(p => p.BopDescId == bopNode.BopDescId && p.ParentCode.StartsWith(bopNode.NodeCode));
                        //3.删除改节点的数据
                        await _bopNodeRepository.DeleteAsync(id);
                        //获取计划调度信息 如果有连同子集计划调度信息删除
                        var temProduction = _productionSchedulerRepository.GetAll().Where(d => d.NodeId == id).FirstOrDefault();
                        if (temProduction != null)
                        {
                            _productionSchedulerRepository.Delete(temProduction);
                        }

                        _iOperationHistoryAppService.InsertOperationLog(bopNode.BopDescId, 0, 8, "删除" + bopNode.NodeName + "节点");
                    }
                    else
                    {
                        throw new UserFriendlyException("存在绑定工艺规程文件的子节点,不能删除!");
                    }
                }
                else
                {
                    throw new UserFriendlyException("该节点已绑定工艺规程文件,不能删除!");
                }
            }
        }
        /// <summary>
        /// 节点树的生成
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="ParentId"></param>
        private void BindTree(TreeClass parentNode, Guid ParentId)
        {
            var bopNodeList = _bopNodeRepository.GetAll().Where(c => c.ParentId == ParentId).OrderBy(d => d.CreationTime);
            //var list = ObjectMapper.Map<List<BopNodeDto>>(bopNodeList);
            foreach (var item in bopNodeList)
            {
                TreeClass tree = new TreeClass();
                tree.Id = item.Id;
                tree.ParentId = item.ParentId;
                tree.NodeDrawingNo = item.NodeDrawingNo;
                tree.NodeName = item.NodeName;
                if (string.IsNullOrEmpty(item.ProcessCode))
                    tree.IsRelation = 0;
                else
                    tree.IsRelation = 1;
                tree.NodeLevel = item.NodeLevel;   //NodeLevel;
                tree.ParentCode = item.ParentCode;
                tree.NodeCode = item.NodeCode;

                tree.IsLeaf = item.IsLeaf;
                tree.IsExport = item.IsExport;
                tree.PadName = item.PadName;
                tree.PadId = item.PadId;
                //递归性质，函数内调用自身函数
                //NodeLevel++;
                BindTree(tree, item.Id);
                //NodeLevel--;
                //递归结束的终点条件
                parentNode.children.Add(tree);
            }
        }
        /// <summary>
        /// Tree Show
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public List<TreeClass> GetTreeGrid(GetBopNodeTreeListInput input)
        {

            TreeClass treeNodes = new TreeClass();
            BindTree(treeNodes, input.BopId);
            return treeNodes.children.ToList();
        }
        ///// <summary>
        ///// 循环生成工序和工步树,方法1：不可取，弃用
        ///// </summary>
        ///// <param name="parentNode"></param>
        ///// <param name="NodeId"></param>
        //private void BindWorkStep1(TreeClass parentNode, Guid NodeId)
        //{
        //    //获取节点信息，获得工艺规程编码
        //    var bomNode = _bopNodeRepository.FirstOrDefault(x => x.Id == NodeId);
        //    string processCode = bomNode.ProcessCode;
        //    //根据工艺规程编码获取工艺文件表Id,已关联文件
        //    if (!string.IsNullOrEmpty(processCode))
        //    {
        //        var tech = _techniqueEntityRepository.FirstOrDefault(x => x.TechniqueNumber == processCode);
        //        Guid techId = tech.Id;
        //        //工艺文件表关联工序表
        //        var processesList = _processesEntityRepository.GetAll().Where(c => c.TechniqueEntityId == techId).OrderBy(x => x.ProcessesSequence).ToList();
        //        foreach (var item in processesList)
        //        {
        //            TreeClass tree = new TreeClass();
        //            tree.Id = item.Id;
        //            tree.ParentId = NodeId;
        //            tree.NodeDrawingNo = "工序" + item.ProcessesSequence.ToString() + " ";
        //            tree.NodeName = item.ProcessesName;
        //            tree.IsRelation = 0;
        //            tree.NodeLevel = 8;
        //            tree.PadName = item.PadName;
        //            tree.PadId = item.PadId;

        //            //查询工步
        //            var workStepList = _workStepEntityRepository.GetAll().Where(c => c.ProcessesEntityId == item.Id).OrderBy(x => x.WorkStepNumber).ToList();
        //            foreach (var witem in workStepList)
        //            {
        //                TreeClass wtree = new TreeClass();
        //                wtree.Id = witem.Id;
        //                wtree.ParentId = item.Id;
        //                wtree.NodeDrawingNo = "工步" + item.ProcessesSequence.ToString() + "-" + witem.WorkStepNumber.ToString();
        //                wtree.NodeName = "";//witem.WorkStepName  这个值数据库有问题
        //                wtree.IsRelation = 0;
        //                wtree.NodeLevel = 9;
        //                tree.children.Add(wtree);
        //            }
        //            treeNodes.Add(tree);
        //        }
        //    }
        //}
        /// <summary>
        /// 循环生成工序和工步树
        /// </summary>
        /// <param name="NodeId"></param>
        private void BindWorkStep(Guid NodeId, TreeClass node)
        {
            //获取节点信息的工艺规程编码
            var bomNode = _bopNodeRepository.FirstOrDefault(x => x.Id == NodeId);
            string processCode = bomNode.ProcessCode;
            //根据工艺规程编码获取工艺文件表Id,已关联文件
            var tech = _techniqueEntityRepository.FirstOrDefault(x => x.Id == bomNode.TechniqueEntityId);
            if (tech == null) return;
            Guid techId = tech.Id;
            //获取工序和工步的信息，并做相应的排序
            var processesList = _processesEntityRepository.GetAllIncluding(p => p.WorkStepEntities).Where(p => p.TechniqueEntityId == techId).OrderBy(n => n.ProcessesSequence).AsNoTracking().ToList();
            //循环遍历，往Node里面赋值
            foreach (var item in processesList)
            {
                TreeClass tree = new TreeClass();
                tree.Id = item.Id;
                tree.ParentId = NodeId;
                tree.NodeDrawingNo = "工序" + item.ProcessesSequence.ToString() + " ";
                tree.NodeName = item.ProcessesName;
                tree.IsRelation = 0;
                tree.NodeLevel = 8;
                item.WorkStepEntities = item.WorkStepEntities.OrderBy(r => r.WorkStepNumber).ToList();
                //查询工步
                foreach (var witem in item.WorkStepEntities)
                {
                    TreeClass wtree = new TreeClass();
                    wtree.Id = witem.Id;
                    wtree.ParentId = item.Id;
                    wtree.NodeDrawingNo = "工步" + item.ProcessesSequence.ToString();// + "-"+ witem.WorkStepNumber.ToString();
                    wtree.NodeName = witem.WorkStepNumber.ToString();//witem.WorkStepName  这个值数据库有问题
                    wtree.IsRelation = 0;
                    wtree.NodeLevel = 9;
                    tree.children.Add(wtree);
                }
                node.children.Add(tree);
            }
        }
        /// <summary>
        /// 工序和工步树生成接口
        /// </summary>
        /// <param name="NodeId"></param>
        /// <returns></returns>
        public List<TreeClass> GetWorkStep(Guid NodeId)
        {
            TreeClass node = new TreeClass();
            BindWorkStep(NodeId, node);
            return node.children.ToList();
        }
        /// <summary>
        ///  工艺文件的导出(根据nodeLevel节点判断，3、4级整本，8级工序，9级工步)
        /// </summary>
        /// <param name="bopNodeId">节点ID</param>
        /// <param name="precossId">工序表ID</param>
        /// <param name="nodeLevel">层级</param>
        public string ExportJsonPackage(Guid bopNodeId, Guid precossId, int nodeLevel)
        {

            string zipPathName = "";
            //只有3、4、8级才能导出文件，
            if ((nodeLevel == 2) || (nodeLevel == 3))
            {
                //导出整本工艺规程
                TechnologyJsonPackageExport(bopNodeId, ref zipPathName);
            }
            else if (nodeLevel == 8)
            {
                //导出该工序所在目录的工艺规程，不包含同级其他工序的工艺规程
                if (!PrecossJsonPackageExport(precossId, bopNodeId, ref zipPathName))
                {
                    throw new Exception("导出Json文件失败!");
                }
            }
            else
            {
                throw new UserFriendlyException("该节点不能导出工艺文件");
            }
            return zipPathName;
        }
        /// <summary>
        /// 整个工艺文件的导出,信息包含：工艺文件,工序,工步  未包含 记录表信息，弃用
        /// </summary>
        /// <param name="nodeId"></param>
        private void TechnologyJsonPackage(Guid nodeId)
        {
            var bomNode = _bopNodeRepository.FirstOrDefault(x => x.Id == nodeId);
            string techniqueNumber = "";
            if (bomNode != null)
            {
                var bopNodeDto = ObjectMapper.Map<BopNodeDto>(bomNode);
                techniqueNumber = bopNodeDto.ProcessCode;
                if (string.IsNullOrEmpty(techniqueNumber))
                    throw new UserFriendlyException("未关联工艺规程文件,请先关联!");
            }
            var datalist = new TechniqueDto();
            var techniques = _techniqueEntityRepository.FirstOrDefault(p => p.TechniqueNumber == techniqueNumber);
            if (techniques != null)
            {
                datalist = ObjectMapper.Map<TechniqueDto>(techniques);
                var processess = _processesEntityRepository.GetAll().Where(p => p.TechniqueEntityId == techniques.Id).OrderBy(p => p.ProcessesSequence).ToList();
                datalist.ProcessesListDto = ObjectMapper.Map<List<ProcessesDto>>(processess);
                foreach (var item in datalist.ProcessesListDto)
                {
                    var workSteps = _workStepEntityRepository.GetAll().Where(p => p.ProcessesEntityId == item.Id).OrderBy(p => p.WorkStepNumber).ToList();
                    item.WorkStepListDto = ObjectMapper.Map<List<WorkStepDto>>(workSteps);
                }
            }
            var technique = ObjectMapper.Map<TechniqueDto>(datalist);

            string path = "../../bop/" + techniques.TechniqueNumber;
            string pathFile = path + "/" + techniques.TechniqueNumber + ".json";
            if (Directory.Exists(path) == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory(path);
            }
            if (!File.Exists(pathFile))  // 判断是否已有相同文件 
            {
                FileStream fs1 = new FileStream(pathFile, FileMode.Create, FileAccess.ReadWrite);
                fs1.Close();
            }
            var listjson = Newtonsoft.Json.JsonConvert.SerializeObject(technique);
            File.WriteAllText(pathFile, listjson);
        }
        /// <summary>
        /// 工序工艺文件的导出，信息包含：工艺文件、当前工序，未包含 记录表信息，弃用
        /// </summary>
        /// <param name="id"></param>
        private void PrecossJsonPackage(Guid id)
        {
            var datalist = new TechniqueDto();
            var pro = _processesEntityRepository.FirstOrDefault(p => p.Id == id);
            var techniques = _techniqueEntityRepository.FirstOrDefault(p => p.Id == pro.TechniqueEntityId);
            if (techniques != null)
            {
                datalist = ObjectMapper.Map<TechniqueDto>(techniques);
                var processess = _processesEntityRepository.GetAll().Where(p => p.Id == id).ToList();
                datalist.ProcessesListDto = ObjectMapper.Map<List<ProcessesDto>>(processess);
                foreach (var item in datalist.ProcessesListDto)
                {
                    var workSteps = _workStepEntityRepository.GetAll().Where(p => p.ProcessesEntityId == item.Id).OrderBy(p => p.WorkStepNumber).ToList();
                    item.WorkStepListDto = ObjectMapper.Map<List<WorkStepDto>>(workSteps);
                }
            }
            var technique = ObjectMapper.Map<TechniqueDto>(datalist);

            string path = "../../bop/" + techniques.TechniqueNumber + "/" + pro.ProcessesName + "(工序" + pro.ProcessesSequence.ToString() + ")";
            string pathFile = path + "/" + techniques.TechniqueNumber + "-" + pro.ProcessesName + ".json";
            if (Directory.Exists(path) == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory(path);
            }
            if (!File.Exists(pathFile))  // 判断是否已有相同文件 
            {
                FileStream fs1 = new FileStream(pathFile, FileMode.Create, FileAccess.ReadWrite);
                fs1.Close();
            }
            var listjson = Newtonsoft.Json.JsonConvert.SerializeObject(technique);
            File.WriteAllText(pathFile, listjson);
        }
        /// <summary>
        /// 工艺文档首页信息查询接口
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<TechniqueDto> GetTechniqueEntity(Guid id)
        {
            //根据节点Id去查询绑定的文档
            var datalist = new TechniqueDto();

            var bopNode = await _bopNodeRepository.FirstOrDefaultAsync(x => x.Id == id);
            if (bopNode != null)
            {
                var tech = _techniqueEntityRepository.FirstOrDefaultAsync(x => x.TechniqueNumber == bopNode.ProcessCode).Result;
                if (tech != null)
                {

                    datalist = ObjectMapper.Map<TechniqueDto>(tech);
                    datalist.PadName = bopNode.PadName;
                    datalist.ExportDate = bopNode.ExportDate;
                    datalist.RelationDate = bopNode.RelationDate;
                }
            }
            return datalist;
        }
        /// <summary>
        /// 维护定额工时
        /// </summary>
        /// <param name="id"></param>
        /// <param name="workingHours"></param>
        /// <returns></returns>
        public async Task<ResultMessage> UpdateWorkingHours(Guid id, decimal workingHours)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                var tech = _techniqueEntityRepository.FirstOrDefaultAsync(x => x.Id == id).Result;
                if (tech != null)
                {
                    tech.WorkingHours = workingHours;
                    await _techniqueEntityRepository.UpdateAsync(tech);
                }
                resultMessage.code = 0;
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }

        /// <summary>
        /// 工艺文件解除绑定
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ResultMessage> UnbindNode(Guid id)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                //加防错，已导出的文件不能解绑
                var bop = await _bopNodeRepository.FirstOrDefaultAsync(c => c.Id == id);
                //默认 bop树导出  bappad导出  计划导出 标识 均没有导出 才可以解除绑定
                if (bop.IsExport == 0 && bop.BopExprot == false && bop.PlanExprot == false)
                {
                    var tech = _techniqueEntityRepository.Get(bop.TechniqueEntityId.Value);

                    var workIdList = await _workStepEntityRepository.GetAllListAsync(d => d.TechniqueEntityId == tech.Id);
                    if (workIdList.Count > 0)
                    {
                        var tempArray = workIdList.Select(d => d.Id).ToList();
                        var loadList = await _loadPieceRepository.GetAllListAsync(d => tempArray.Contains(d.WorkStepEntityId));
                        //判断装入件明细表是否有物料 如果有 是否 配套了 配套状态应先解除配套才可以解绑
                        if (loadList.Count > 0)
                        {
                            var loadIdList = loadList.Select(d => d.Id).ToList();
                            int tempCount = await _storeStockContentRepsitory.CountAsync(d => loadIdList.Contains(d.LoadDetailsId.Value));
                            if (tempCount > 0)
                            {
                                resultMessage.code = 1;
                                resultMessage.Message = "该工艺规程还有已配套的物料,请先解除配套，然后解绑！";
                                return resultMessage;
                                //throw new UserFriendlyException("该工艺规程还有已配套的物料,请先解除配套，然后解绑！");
                            }
                        }
                        var schedulerPro = await _productionSchedulerRepository.GetAllListAsync(d => d.ParentId == bop.Id);
                        //如果解除绑定了 计划数据就可以删除
                        foreach (var item in schedulerPro)
                        {
                            await _productionSchedulerRepository.DeleteAsync(item);
                            await _productionSchedulerRepository.DeleteAsync(d => d.ParentId == item.NodeId);
                        }
                    }
                    tech.Edition = "";
                    tech.FileStatus = FileStatus.新增; //解除绑定后 一体化文件状态变为新增
                    await _techniqueEntityRepository.UpdateAsync(tech);

                    bop.ProcessCode = null;
                    bop.TechniqueEntityId = null;
                    await _bopNodeRepository.UpdateAsync(bop);
                    var bopDesc = _bopDescRepository.Get(bop.BopDescId);
                    bopDesc.ProcessStatus = ProcessStatus.维护中;
                    await _bopDescRepository.UpdateAsync(bopDesc);
                    _iOperationHistoryAppService.InsertOperationLog(bop.BopDescId, 0, 4, bop.NodeName + "解除绑定工艺规程");
                    //如果有路线信息应该重新指定父节点 
                    var bopLines = await _processLineRepository.GetAllListAsync(d => d.PPtr == bop.Id);
                    if (bopLines.Count() > 0)
                    {
                        foreach (var item in bopLines)
                        {
                            item.PPtr = tech.Id;
                            item.BopDescId = null;
                            await _processLineRepository.UpdateAsync(item);
                        }

                    }
                    resultMessage.code = 0;
                    return resultMessage;
                }
                else
                {
                    resultMessage.code = 1;
                    resultMessage.Message = "已导出过，不能解绑";
                    return resultMessage;
                    //throw new UserFriendlyException("已导出过，不能解绑");
                }
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }
        /// <summary>
        /// 获取工序和工步信息方法1：弃用
        /// </summary>
        /// <param name="id"></param>
        private List<QualityProcessesDto> GetProcessesEntity1(Guid id)
        {
            //获取节点信息，获得工艺规程编码
            var datalist = new List<QualityProcessesDto>();
            var bomNode = _bopNodeRepository.FirstOrDefault(x => x.Id == id);
            string processCode = bomNode.ProcessCode;
            //根据工艺规程编码获取工艺文件表Id,已关联文件
            if (!string.IsNullOrEmpty(processCode))
            {
                var tech = _techniqueEntityRepository.FirstOrDefault(x => x.TechniqueNumber == processCode);
                Guid techId = tech.Id;
                //工艺文件表关联工序表
                var processesList = _processesEntityRepository.GetAll().Where(c => c.TechniqueEntityId == techId).OrderBy(x => x.ProcessesSequence).ToList();

                datalist = ObjectMapper.Map<List<QualityProcessesDto>>(processesList);
                foreach (var item in datalist)
                {
                    var workSteps = _workStepEntityRepository.GetAll().Where(p => p.ProcessesEntityId == item.Id).OrderBy(p => p.WorkStepNumber).ToList();
                    item.WorkStepListDto = ObjectMapper.Map<List<QualityWorkStepDto>>(workSteps);
                }
            }
            return ObjectMapper.Map<List<QualityProcessesDto>>(datalist);
        }
        /// <summary>
        /// 获取工序和工步信息方法
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<QualityProcessesDto> GetProcessesEntity(Guid id)
        {
            /* 示例代码
               var s = _techniqueEntityRepository.GetAllIncluding(p => p.ProcessesEntities).FirstOrDefault(p => p.TechniqueNumber == techniqueNumber);
               s.ProcessesEntities = s.ProcessesEntities.OrderBy(n => n.ProcessesSequence).ToList();
               s.ProcessesEntities.ToList().ForEach(q => q.WorkStepEntities = q.WorkStepEntities.OrderBy(r => r.WorkStepNumber).ToList());
            */
            //获取节点信息的工艺规程编码
            var dataList = new List<QualityProcessesDto>();
            var bomNode = _bopNodeRepository.FirstOrDefault(x => x.Id == id);
            if (bomNode != null)
            {
                string processCode = bomNode.ProcessCode;
                //根据工艺规程编码获取工艺文件表Id,已关联文件
                var tech = _techniqueEntityRepository.FirstOrDefault(x => x.TechniqueNumber == processCode);
                Guid techId = tech.Id;
                //获取工序和工步的信息，并做相应的排序
                var processesList = _processesEntityRepository.GetAllIncluding(p => p.WorkStepEntities).Where(p => p.TechniqueEntityId == techId).OrderBy(n => n.ProcessesSequence).ToList();
                processesList.ToList().ForEach(q => q.WorkStepEntities = q.WorkStepEntities.OrderBy(r => r.WorkStepNumber).ToList());
                dataList = ObjectMapper.Map<List<QualityProcessesDto>>(processesList);
            }
            return dataList;
        }
        /// <summary>
        /// 获取工艺文件所有的信息,弃用
        /// </summary>
        /// <param name="tNumber"></param>
        /// <returns></returns>
        private List<TechniqueDto> GetTechniqueAllInfo(string tNumber)
        {
            var s = _techniqueEntityRepository.GetAllIncluding(p => p.ProcessesEntities).FirstOrDefault(p => p.TechniqueNumber == tNumber);
            s.ProcessesEntities = s.ProcessesEntities.OrderBy(n => n.ProcessesSequence).ToList();
            s.ProcessesEntities.ToList().ForEach(q => q.WorkStepEntities = q.WorkStepEntities.OrderBy(r => r.WorkStepNumber).ToList());
            //map
            var datalist = new List<TechniqueDto>();
            return datalist;
        }
        /// <summary>
        /// 整个工艺文件的导出,信息包含：工艺文件,工序,工步,记录表信息
        /// </summary>
        /// <param name="nodeId"></param>
        private void TechnologyJsonPackageExport(Guid nodeId, ref string zipPathName)
        {
            var bomNode = _bopNodeRepository.FirstOrDefault(x => x.Id == nodeId);
            string techniqueNumber = "";
            if (bomNode != null)
            {
                var bopNodeDto = ObjectMapper.Map<BopNodeDto>(bomNode);
                techniqueNumber = bopNodeDto.ProcessCode;
                if (string.IsNullOrEmpty(techniqueNumber))
                    throw new UserFriendlyException("未关联工艺规程文件,请先关联!");

                CreateOrUpdateBopNodeInput crInput = new CreateOrUpdateBopNodeInput();
                BopNodeEditDto bopNodeEdit = new BopNodeEditDto();
                bopNodeEdit = ObjectMapper.Map<BopNodeEditDto>(bopNodeDto);
                crInput.BopNode = bopNodeEdit;
                if (!GetTechnologyJsonPackage(techniqueNumber, crInput, ref zipPathName))
                {
                    throw new Exception("导出Json文件失败!");
                }
            }
        }
        /// <summary>
        /// 获取工艺文件所有的信息
        /// </summary>
        /// <param name="techniqueNumber"></param>
        /// <param name="bopNode"></param>
        private bool GetTechnologyJsonPackage(string techniqueNumber, CreateOrUpdateBopNodeInput bopNode, ref string zipPathName)
        {
            //获取信息步骤; 规程- 工序 -工步
            var datalist = new TechniqueOutDto();
            List<TableNameDictionary> tableNameDictionary = new List<TableNameDictionary>();
            var techniques = _techniqueEntityRepository.FirstOrDefault(p => p.TechniqueNumber == techniqueNumber && p.Id == bopNode.BopNode.TechniqueEntityId);//规程
            if (techniques != null)
            {
                datalist = ObjectMapper.Map<TechniqueOutDto>(techniques);
                var processess = _processesEntityRepository.GetAll().Where(p => p.TechniqueEntityId == techniques.Id).OrderBy(p => p.ProcessesSequence).ToList();//工序
                datalist.ProcessesListDto = ObjectMapper.Map<List<ProcessesOutDto>>(processess);
                foreach (var item in datalist.ProcessesListDto)
                {
                    if (!string.IsNullOrEmpty(item.ProcessesExplain))
                    {
                        item.ProcessesExplain = item.ProcessesExplain.Replace("../DownLoadFileRootPath/" + techniqueNumber + "/", "");
                    }
                    var workSteps = _workStepEntityRepository.GetAll().Where(p => p.ProcessesEntityId == item.Id).OrderBy(p => p.WorkStepNumber).ToList(); //工步
                    item.WorkStepListDto = ObjectMapper.Map<List<WorkStepOutDto>>(workSteps);

                    foreach (var workStep in item.WorkStepListDto)
                    {
                        if (!string.IsNullOrEmpty(workStep.WorkStepContent))
                        {
                            workStep.WorkStepContent = workStep.WorkStepContent.Replace("../DownLoadFileRootPath/" + techniqueNumber + "/", "");
                        }
                        // GetImageStr(workStep.WorkStepContent);
                        WorkStepJsonAnalysis(workStep, tableNameDictionary); //工步下动态关联表
                    }
                }
                // json中加入权限控制模块
                var userPermissions = GetUserPermissions();
                List<PadJurisdictionDto> dtolst = new List<PadJurisdictionDto>();
                dtolst = userPermissions.Result;
                datalist.PadJurisdictionListDto = dtolst;
                //json中增加发次id、部套节点id
                datalist.BopDescId = bopNode.BopNode.BopDescId;
                datalist.BopNodeId = bopNode.BopNode.Id;
                var bopTaskOutDto = ObjectMapper.Map<BopTaskOutDto>(_bopDescRepository.GetAll().Where(d => d.Id == bopNode.BopNode.BopDescId).First());
                bopTaskOutDto.TechniqueTask = datalist;
                string path = "../../Bop/" + techniques.TechniqueNumber + "/" + techniques.TechniqueNumber + "/";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //by2022/12/6
                string srcPatch = Environment.CurrentDirectory + "/wwwroot/DownLoadFileRootPath/" + techniques.TechniqueNumber + "/";
                if (!Directory.Exists(srcPatch))
                {
                    Directory.CreateDirectory(srcPatch);
                }
                if (CopyDir(srcPatch, path))
                {
                    string fp = path + techniques.TechniqueNumber + ".json"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
                    if (File.Exists(fp))  // 判断是否已有相同文件 
                    {
                        File.Delete(fp);
                    }
                    var listjson = Newtonsoft.Json.JsonConvert.SerializeObject(bopTaskOutDto);
                    File.WriteAllText(fp, listjson);
                    string zipdir = "../../Bop/" + techniques.TechniqueNumber + "/Zip/";
                    if (!Directory.Exists(zipdir))
                    {
                        Directory.CreateDirectory(zipdir);
                    }
                    zipPathName = zipdir + techniques.TechniqueNumber + ".zip";
                    if (File.Exists(zipPathName))
                    {
                        File.Delete(zipPathName);
                    }
                }
                else
                {
                    return false;
                }
          
               
                //压缩方法而已 后续可以自己扩展  made by lhd
                CompressMulti(new List<string> { path }, zipPathName, true);
                return true;
                //string fp = path + techniques.TechniqueNumber + ".json"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
                //if (File.Exists(fp))  // 判断是否已有相同文件 
                //{
                //    File.Delete(fp);
                //}
                //var listjson = Newtonsoft.Json.JsonConvert.SerializeObject(bopTaskOutDto);
                //File.WriteAllText(fp, listjson);
                ////string srcPatch = "../../tech/" + techniques.TechniqueNumber + "/";    20210709  Edit by LHD
                //string srcPatch = Environment.CurrentDirectory + "/wwwroot/DownLoadFileRootPath/" + techniques.TechniqueNumber + "/";
                //if (!Directory.Exists(srcPatch))
                //{
                //    Directory.CreateDirectory(srcPatch);
                //}
                ////动态抓取文件 然后打包发送
                //if (CopyDir(srcPatch, path))
                //{
                //    string zipdir = "../../Bop/" + techniques.TechniqueNumber + "/Zip/";
                //    if (!Directory.Exists(zipdir))
                //    {
                //        Directory.CreateDirectory(zipdir);
                //    }
                //    zipPathName = zipdir + techniques.TechniqueNumber + ".zip";
                //    if (File.Exists(zipPathName))
                //    {
                //        File.Delete(zipPathName);
                //    }
                //    //压缩方法而已 后续可以自己扩展  made by lhd
                //    CompressMulti(new List<string> { path }, zipPathName, true);
                //    //ZipFile.CreateFromDirectory(path, zipPathName);
                //    return true;
                //}
                //else
                //{
                //    return false;
                //}
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 工序   --->工艺文件的导出，信息包含：工艺文件、当前工序，所有工步记录表信息
        /// </summary>
        /// <param name="precossId"></param>
        /// <param name="bopNodeId"></param>
        /// <param name="zipPathName"></param>
        /// <returns></returns>
        private bool PrecossJsonPackageExport(Guid precossId, Guid bopNodeId, ref string zipPathName)
        {
            try
            {
                List<TableNameDictionary> tableNameDictionary = new List<TableNameDictionary>();
                //最终导出的工艺出参
                var datalist = new TechniqueOutDto();
                //根据工序id查询本工序信息
                var pro = _processesEntityRepository.FirstOrDefault(p => p.Id == precossId);
                //根据工序关联的工艺id查询上一级工艺信息
                var techniques = _techniqueEntityRepository.FirstOrDefault(p => p.Id == pro.TechniqueEntityId);
                //根据布套节点id查询工序信息所在的布套节点
                var bopNode = _bopNodeRepository.FirstOrDefault(x => x.Id == bopNodeId);
                if (bopNode == null)
                {
                    throw new UserFriendlyException("导出Json文件失败!");
                }
                //根据工序id查询关联的所有工步信息
                var workSteps = _workStepEntityRepository.GetAll().Where(p => p.ProcessesEntityId == pro.Id).OrderBy(p => p.WorkStepNumber).ToList();
                //工艺实体转工艺出参
                datalist = ObjectMapper.Map<TechniqueOutDto>(techniques);
                //工序实体转工序出参
                var dto = ObjectMapper.Map<ProcessesOutDto>(pro);
                //工步实体转工步出参
                dto.WorkStepListDto = ObjectMapper.Map<List<WorkStepOutDto>>(workSteps);
                //循环工步，绑定记录表信息
                foreach (var workStep in dto.WorkStepListDto)
                {
                    if (!string.IsNullOrEmpty(workStep.WorkStepContent))
                    {
                        workStep.WorkStepContent = workStep.WorkStepContent.Replace("../DownLoadFileRootPath/" + techniques.TechniqueNumber + "/", "");
                    }
                    WorkStepJsonAnalysis(workStep, tableNameDictionary);
                }
                //将绑定记录表的工序信息赋给工艺信息的第一个工序
                datalist.ProcessesListDto[0] = dto;
                // json中加入权限控制模块
                var userPermissions = GetUserPermissions();
                List<PadJurisdictionDto> dtolst = new List<PadJurisdictionDto>();
                dtolst = userPermissions.Result;
                datalist.PadJurisdictionListDto = dtolst;
                //json中增加发次id、布套节点id
                datalist.BopDescId = bopNode.BopDescId;
                datalist.BopNodeId = bopNode.Id;

                var bopTaskOutDto = ObjectMapper.Map<BopTaskOutDto>(_bopDescRepository.GetAll().Where(d => d.Id == bopNode.BopDescId).First());

                bopTaskOutDto.TechniqueTask = datalist;
                string path = "../../Bop/" + techniques.TechniqueNumber + "/Process/" + techniques.TechniqueNumber + "_" + dto.ProcessesSequence + "/";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fp = path + techniques.TechniqueNumber + "_" + dto.ProcessesSequence + ".json";
                if (File.Exists(fp))  // 判断是否已有相同文件 
                {
                    File.Delete(fp);
                }
                var listjson = Newtonsoft.Json.JsonConvert.SerializeObject(bopTaskOutDto);
                File.WriteAllText(fp, listjson);
                //赋值相关文件导目录文件夹
                string srcPatch = "../../tech/" + techniques.TechniqueNumber + "/";
                if (!Directory.Exists(srcPatch))
                {
                    Directory.CreateDirectory(srcPatch);
                }
                if (CopyDir(srcPatch, path))
                {
                    string zipdir = "../../Bop/" + techniques.TechniqueNumber + "/Zip/";
                    if (!Directory.Exists(zipdir))
                    {
                        Directory.CreateDirectory(zipdir);
                    }
                    zipPathName = zipdir + techniques.TechniqueNumber + "_" + dto.ProcessesSequence + ".zip";
                    if (File.Exists(zipPathName))
                    {
                        File.Delete(zipPathName);
                    }

                    CompressMulti(new List<string> { path }, zipPathName, true);
                    //ZipFile.CreateFromDirectory(path, zipPathName);
                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch// (Exception ex)
            {
                return false;
                //throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 工步  --->工艺文件的导出，信息包含：工艺文件、工序，当前工步的记录表信息 弃用
        /// </summary>
        /// <param name="id"></param>
        private void WorkStepJsonPackageExport(Guid id)
        {

            var workSteps = _workStepEntityRepository.FirstOrDefault(p => p.Id == id);
            if (workSteps == null)
                throw new UserFriendlyException("该工步未关联工艺规程文件!");
            var WorkStep = ObjectMapper.Map<WorkStepOutDto>(workSteps);

            //WorkStep.Hatch = ObjectMapper.Map<List<HatchOutDto>>(_hatchEntityRepository.GetAllIncluding(a => a.ThirdInspection, b => b.RecordRequirements).Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            ////WorkStep.HatchState = ObjectMapper.Map<List<HatchStateOutDto>>(_hatchStateRepository.GetAllIncluding(a => a.ThirdInspection, b => b.RecordRequirements).Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            ////WorkStep.MandatoryInspection = ObjectMapper.Map<List<MandatoryInspectionOutDto>>(_mandatoryInspectionRepository.GetAllIncluding(b => b.MultiMediaEntity).Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            //WorkStep.Moment = ObjectMapper.Map<List<MomentOutDto>>(_momentRepository.GetAll().Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            //WorkStep.MomentRecord = ObjectMapper.Map<List<MomentRecordOutDto>>(_momentRecordRepository.GetAllIncluding(a => a.ThirdInspection).Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            ////WorkStep.PlugState = ObjectMapper.Map<List<PlugStateOutDto>>(_plugStateRepository.GetAllIncluding(a => a.ThirdInspection, b => b.MultiMediaEntity).Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            ////WorkStep.ProductGrounding = ObjectMapper.Map<List<ProductGroundingOutDto>>(_productGroundingRepository.GetAllIncluding(a => a.ThirdInspection, b => b.Currency).Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            ////WorkStep.StatusCheck = ObjectMapper.Map<List<StatusCheckOutDto>>(_statusCheckRepository.GetAll().Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            //WorkStep.TransducerConverter = ObjectMapper.Map<List<TransducerConverterOutDto>>(_transducerConverteritory.GetAllIncluding(a => a.ThirdInspection).Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            //WorkStep.MultiMedia = ObjectMapper.Map<List<MultiMediaOutDto>>(_multiMediaRepository.GetAll().Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            //WorkStep.LoadPiece = ObjectMapper.Map<List<LoadPieceOutDto>>(_loadPieceRepository.GetAll().Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            //WorkStep.Video = ObjectMapper.Map<List<VideoOutDto>>(_videoEntityRepository.GetAll().Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            ////WorkStep.MakeResources = ObjectMapper.Map<List<ZZResourcesOutDto>>(_zZResourcesEntityRepository.GetAll().Where(p => p.WorkStepEntityId == WorkStep.Id).OrderBy(n => n.Index));
            ////WorkStep.QualityRecord = ObjectMapper.Map<List<QualityRecordOutDto>>(_qualityRecordEntityRepository.GetAll().Where(p => p.WorkStepEntityId == WorkStep.Id));
            //}

            string fp = "../../Bop/" + WorkStep.WorkStepName + ".json";
            if (!File.Exists(fp))  // 判断是否已有相同文件 
            {
                FileStream fs1 = new FileStream(fp, FileMode.Create, FileAccess.ReadWrite);
                fs1.Close();
            }
            var listjson = Newtonsoft.Json.JsonConvert.SerializeObject(WorkStep);
            File.WriteAllText(fp, listjson);
        }
        /// <summary>
        /// 解析工步下的所有记录表
        /// </summary>
        /// <param name="workStep"></param>
        private void WorkStepJsonAnalysis(WorkStepOutDto workStep, List<TableNameDictionary> tableNameDictionary)
        {
            //动态获取工步下的关联表 逻辑不复杂 只是表多而已

            //实体表
            //装入件明细 InsertDetails
            //制造资源   ManufacturingResources
            //视频       Video

            //通用总装数据记录表 AssembleDto 
            //通用记录表     GeneralRecordsDto
            //胶液配比情况记录表 GlueSolutionDto
            //舱口盖开闭记录表  HatchOpenShutDto
            //进箱（舱）登记表  InCabinDto
            //具有证明书的主要零件记录表 MainPartsDto
            //力矩记录表 MomentRecordingDto
            //多媒体记录表 MultimediaRecordDto
            //通用力矩复校记录表 TorqueReCalibrationDto
            //质量控制记录表 QualityControlDto
            //电缆插头防水防热记录表 CablePlugWaterFireProofDto
            //波纹管变形记录表 BellowsDeformationDto
            //电连接器插接记录表 ElectricalConnectInsertionDto
            //舱口盖开闭测试记录表 HatchOpenShutTestDto
            //产品接地状态检查记录表 ProductGroundingStatusDto
            //强制检验点记录表 ForcedCheckpointDto 
            //自动关闭口盖检查记录表 AutomaticShutoffDto
            //伺服机构工艺拉杆长度记录表 ServomechanismDto
            //状态检查表 StatusCheckDto
            //问题记录表 ProblemRecordDto
            //爆索尺寸测量记录表 DetonatingCableSizeDto
            //整流罩/星箭分离弹簧压缩数据记录表 ReleaseSpringCompressionDto
            //载荷支架组合体形位数据记录表 LoadBracketDto
            //设计签署总装数据记录表 DesignGeneralAssembleDto
            //管路活门气密点检查记录表皂泡法 SoapBubbleDto	
            //管路活门气密点检查记录表氦质谱法 HeliumMassSpectrometryDto	
            //除了打保险防松外的总装直属件记录表 FinalAssemblyPartsDto
            //传感器安装测试记录情况统计记录表 SensorInstallationDto
            //插头状态检查表 PlugStatusDto
            //惯组安装记录表1 FirstIMUInstallationDto
            //惯组安装记录表2 SecondIMUInstallationDto
            //电缆高度测量记录表 CableHeightDto
            //电缆剥线试验记录表低频 LowFrequencyCableStrippingDto
            //压接实验测量记录表低频 LowCrimpingExperimentDto
            //电缆剥线试验记录表高频 HighFrequencyCableStrippingDto	
            //仪器接收检查记录表 InstrumentCheckDto
            //电缆接收检查记录表 CableReceivingInspectionDto
            //箭地接口保护件检查记录表 ArrowInterfaceProtectCheckDto
            //通用检查记录表  InspectionRecordDto
            //对接面形位记录表  DockSurfaceMorphemeDto
            //整流罩锉修记录表 FilingFileRepairDto
            //整流罩安装后检查记录表 CheckFairingAfterInstallationDto
            //导管检查记录表  CatheterizationDto
            //管路上箭前吹除记录表 BlowPipeArrowDto
            //气封管流量测试记录表 GasPipeTestDto
            //阀门气瓶过滤器流量计输送管金属软管等检查记录表 ValvesGasInspectionDto
            //安装距离记录表 InstallationDistanceDto
            //小导管卡箍间距测量表 MeasurementSpacingConduitDto
            //未按要求施加力矩及未打保险防松记录表 FailureAequiredLoosInsuranceDto
            //分解重装记录表 DisassemblyReassemblyDto
            //配合七零三绝热记录表 Insulation703Dto
            //绝热去除记录表 AdiabaticRemovalDto
            //连续拧紧环节力矩复校记录表 CalibrationContinuousTorqueDto
            //管路垫块安装情况记录表 InstallationPipeCushionDto
            //箭体结构防水记录表 ArrowStructureWaterproofDto
            //搭接线安装部位防水记录表 WaterproofInstallationLapdDto
            tableNameDictionary.Clear();
            //Dictionary<string, FiledNodeMap> filedMap = new Dictionary<string, FiledNodeMap>();

            Common.TableMapConfig tableMapConfig = new Common.TableMapConfig();
            //返给前台的表头 对应字典
            Dictionary<string, FiledNodeMap> filedMap = tableMapConfig.InitFiledNodeMap();
            ////实体表
            //装入件明细
            var InsertDetailsEntitys = _loadPieceRepository.GetAll().Where(p => p.WorkStepEntityId == workStep.Id).OrderBy(n => n.Sort);
            if (InsertDetailsEntitys.Count() > 0)
            {
                workStep.InsertDetails = ObjectMapper.Map<List<InsertDetailsDto>>(InsertDetailsEntitys.OrderBy(n => n.Index));
                if (workStep.InsertDetails.Count > 0)
                {
                    TableNameDictionary table = new TableNameDictionary();
                    table.tablekey = "insertDetails";
                    table.tableName = "装入件明细";
                    table.FiledDesc = filedMap[table.tableName].filedValue;
                    table.FiledName = filedMap[table.tableName].filedKey;
                    table.Sort = workStep.InsertDetails.First().Sort;
                    tableNameDictionary.Add(table);
                    //装入件这个表处理的时候 增加一张附表 统计 各个物料配套的数据 
                    List<InsertDetailsScheduleDto> schedules = new List<InsertDetailsScheduleDto>();
                    for (int i = 0; i < workStep.InsertDetails.Count; i++)
                    {
                        InsertDetailsScheduleDto temp = new InsertDetailsScheduleDto();
                        temp.Id = workStep.InsertDetails[i].Id;
                        var stockList = _storeStockContentRepsitory.GetAll().Where(d => d.LoadDetailsId == temp.Id).ToList();
                        if (stockList.Count > 0)
                        {
                            temp.SuiteStock = stockList.Count;
                            var temPut = (from cc in stockList.Select(d => d.StorePutContentId).Distinct()
                                          join mm in _storePutContentRepsitory.GetAll() on cc equals mm.Id
                                          select new SuiteDetails
                                          {
                                              SuiteStock = stockList.Count(d => d.StorePutContentId == cc),
                                              ReleaseOrder = mm.ReleaseOrder,
                                              QualifiedNumber = mm.QualifiedNumber
                                          }).ToList();
                            temp.SuiteDetailsList = temPut;

                        }
                        else
                        {
                            temp.SuiteStock = 0;
                        }
                        schedules.Add(temp);
                    }
                    workStep.InsertDetailsSchedule = schedules;
                    //join pp in _storePutContentRepsitory.GetAll() on cc.StorePutContentId equals pp.Id 

                }
            }
            else
            {
                workStep.InsertDetails = new List<InsertDetailsDto>();
            }
            //制造资源
            var ManufacturingResourcesEntitys = _makeResourcesEntityRepository.GetAll().Where(p => p.WorkStepEntityId == workStep.Id).OrderBy(n => n.Sort).ToList();
            if (ManufacturingResourcesEntitys.Count() > 0)
            {
                workStep.ManufacturingResources = ObjectMapper.Map<List<ManufacturingResourcesDto>>(ManufacturingResourcesEntitys.OrderBy(n => n.Index));
                if (workStep.ManufacturingResources.Count > 0)
                {
                    TableNameDictionary table = new TableNameDictionary();
                    table.tablekey = "manufacturingResources";
                    table.tableName = "制造资源";
                    table.FiledDesc = filedMap[table.tableName].filedValue;
                    table.FiledName = filedMap[table.tableName].filedKey;
                    table.Sort = workStep.ManufacturingResources.First().Sort;
                    tableNameDictionary.Add(table);
                }
            }
            else
            {
                workStep.ManufacturingResources = new List<ManufacturingResourcesDto>();
            }
            //视频
            var videoEntityEntitys = _videoEntityRepository.GetAll().Where(p => p.WorkStepEntityId == workStep.Id);
            if (videoEntityEntitys.Count() > 0)
            {
                workStep.Video = ObjectMapper.Map<List<VideoFrequencyDto>>(videoEntityEntitys.OrderBy(n => n.Index));
                if (workStep.Video.Count > 0)
                {
                    TableNameDictionary table = new TableNameDictionary();
                    table.tablekey = "video";
                    table.tableName = "视频";
                    table.FiledDesc = filedMap[table.tableName].filedValue;
                    table.FiledName = filedMap[table.tableName].filedKey;
                    table.Sort = workStep.Video.First().Sort;
                    tableNameDictionary.Add(table);
                }
            }
            else
            {
                workStep.Video = new List<VideoFrequencyDto>();
            }
            //动态表
            var tableData = _tableBaseEntity.GetAllIncluding(a => a.RecordRequirements, b => b.InspectionSignature, c => c.MeasuredResult, d => d.Environment, e => e.MultiMedia).Where(d => d.WorkStepEntityId == workStep.Id);
            foreach (var item in tableData)
            {
                if (item.InspectionSignature != null)
                {
                    if (item.InspectionSignature.InspectionSignatureName == null)
                    {
                        item.InspectionSignature.FirstOperator = "不需要";
                        item.InspectionSignature.SecondOperator = "不需要";
                        item.InspectionSignature.ThirdOperator = "不需要";
                        item.InspectionSignature.FourthOperator = "不需要";
                        item.InspectionSignature.FifthOperator = "不需要";
                    }
                }
            }
            var tableNameArry = tableData.Select(d => d.FormName).Distinct().ToArray();
            for (int i = 0; i < tableNameArry.Count(); i++)
            {
                var query = tableData.Where(d => d.FormName == tableNameArry[i]);
                if (tableNameArry[i] == "通用总装数据记录表")
                {
                    var data = (ObjectMapper.Map<List<AssembleDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.Assemble = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "assemble";
                        table.tableName = "通用总装数据记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.Assemble = new List<AssembleDto>();
                    }
                }
                if (tableNameArry[i] == "通用记录表")
                {
                    var data = (ObjectMapper.Map<List<GeneralRecordsDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.GeneralRecords = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "generalRecords";
                        table.tableName = "通用记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);

                    }
                    else
                    {
                        workStep.GeneralRecords = new List<GeneralRecordsDto>();
                    }
                }
                if (tableNameArry[i] == "胶液配比情况记录表")
                {
                    var data = (ObjectMapper.Map<List<GlueSolutionDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.GlueSolution = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "glueSolution";
                        table.tableName = "胶液配比情况记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);

                    }
                    else
                    {
                        workStep.GlueSolution = new List<GlueSolutionDto>();
                    }
                }
                if (tableNameArry[i] == "舱口盖开闭记录表")
                {
                    var data = (ObjectMapper.Map<List<HatchOpenShutDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.Hatch = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "hatch";
                        table.tableName = "舱口盖开闭记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.Hatch = new List<HatchOpenShutDto>();
                    }
                }
                if (tableNameArry[i] == "进箱舱登记表")
                {
                    var data = (ObjectMapper.Map<List<InCabinDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InCabin = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "inCabin";
                        table.tableName = "进箱舱登记表";
                        table.FiledDesc = filedMap["进箱舱登记表"].filedValue;
                        table.FiledName = filedMap["进箱舱登记表"].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InCabin = new List<InCabinDto>();
                    }
                }
                if (tableNameArry[i] == "具有证明书的主要零件记录表")
                {
                    var data = (ObjectMapper.Map<List<MainPartsDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.MainParts = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "mainParts";
                        table.tableName = "具有证明书的主要零件记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.MainParts = new List<MainPartsDto>();
                    }
                }
                if (tableNameArry[i] == "力矩记录表")
                {
                    var data = (ObjectMapper.Map<List<MomentRecordingDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.Moment = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "moment";
                        table.tableName = "力矩记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.Moment = new List<MomentRecordingDto>();
                    }
                }
                if (tableNameArry[i] == "通用多媒体记录表")
                {
                    var data = (ObjectMapper.Map<List<MultimediaRecordDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.MultimediaRecord = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "multimediaRecord";
                        table.tableName = "通用多媒体记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.MultimediaRecord = new List<MultimediaRecordDto>();
                    }
                }
                if (tableNameArry[i] == "通用力矩复校记录表")
                {
                    var data = (ObjectMapper.Map<List<TorqueReCalibrationDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.TorqueReCalibration = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "torqueReCalibration";
                        table.tableName = "通用力矩复校记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.TorqueReCalibration = new List<TorqueReCalibrationDto>();
                    }
                }
                if (tableNameArry[i] == "质量控制记录表")
                {
                    var data = (ObjectMapper.Map<List<QualityControlDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.QualityControl = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "qualityControl";
                        table.tableName = "质量控制记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.QualityControl = new List<QualityControlDto>();
                    }
                }
                if (tableNameArry[i] == "电缆插头防水防热记录表")
                {
                    var data = (ObjectMapper.Map<List<CablePlugWaterFireProofDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.CablePlugWaterFireProofControl = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "cablePlugWaterFireProofControl";
                        table.tableName = "电缆插头防水防热记录表";
                        table.FiledDesc = filedMap["电缆插头防水防热记录表"].filedValue;
                        table.FiledName = filedMap["电缆插头防水防热记录表"].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.CablePlugWaterFireProofControl = new List<CablePlugWaterFireProofDto>();
                    }
                }
                if (tableNameArry[i] == "波纹管变形记录表")
                {
                    var data = (ObjectMapper.Map<List<BellowsDeformationDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.BellowsDeformation = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "bellowsDeformation";
                        table.tableName = "波纹管变形记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.BellowsDeformation = new List<BellowsDeformationDto>();
                    }
                }
                if (tableNameArry[i] == "电连接器插接记录表")
                {
                    var data = (ObjectMapper.Map<List<ElectricalConnectInsertionDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ElectricalConnectInsertion = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "electricalConnectInsertion";
                        table.tableName = "电连接器插接记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ElectricalConnectInsertion = new List<ElectricalConnectInsertionDto>();
                    }
                }
                if (tableNameArry[i] == "舱口盖开闭测试记录表")
                {
                    var data = (ObjectMapper.Map<List<HatchOpenShutTestDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.HatchOpenShutTest = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "hatchOpenShutTest";
                        table.tableName = "舱口盖开闭测试记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.HatchOpenShutTest = new List<HatchOpenShutTestDto>();
                    }

                }
                if (tableNameArry[i] == "产品接地状态检查记录表")
                {

                    var data = (ObjectMapper.Map<List<ProductGroundingStatusDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ProductGroundingStatus = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "productGroundingStatus";
                        table.tableName = "产品接地状态检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ProductGroundingStatus = new List<ProductGroundingStatusDto>();
                    }
                }
                if (tableNameArry[i] == "强制检验点记录表")
                {
                    var data = (ObjectMapper.Map<List<ForcedCheckpointDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ForcedCheckpoint = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "forcedCheckpoint";
                        table.tableName = "强制检验点记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ForcedCheckpoint = new List<ForcedCheckpointDto>();
                    }
                }
                if (tableNameArry[i] == "自动关闭口盖检查记录表")
                {
                    var data = (ObjectMapper.Map<List<AutomaticShutoffDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.AutomaticShutoff = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "automaticShutoff";
                        table.tableName = "自动关闭口盖检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.AutomaticShutoff = new List<AutomaticShutoffDto>();
                    }
                }
                if (tableNameArry[i] == "伺服机构工艺拉杆长度记录表")
                {
                    var data = (ObjectMapper.Map<List<ServomechanismDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.Servomechanism = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "servomechanism";
                        table.tableName = "伺服机构工艺拉杆长度记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.Servomechanism = new List<ServomechanismDto>();
                    }
                }
                if (tableNameArry[i] == "状态检查表")
                {
                    var data = (ObjectMapper.Map<List<StatusCheckDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.StatusCheck = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "statusCheck";
                        table.tableName = "状态检查表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.StatusCheck = new List<StatusCheckDto>();
                    }
                }
                if (tableNameArry[i] == "问题记录表")
                {
                    var data = (ObjectMapper.Map<List<ProblemRecordDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ProblemRecord = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "problemRecord";
                        table.tableName = "问题记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ProblemRecord = new List<ProblemRecordDto>();
                    }
                }
                if (tableNameArry[i] == "爆索尺寸测量记录表")
                {
                    var data = (ObjectMapper.Map<List<DetonatingCableSizeDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.DetonatingCableSize = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "detonatingCableSize";
                        table.tableName = "爆索尺寸测量记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.DetonatingCableSize = new List<DetonatingCableSizeDto>();
                    }
                }
                if (tableNameArry[i] == "整流罩星箭分离弹簧压缩数据记录表")
                {
                    var data = (ObjectMapper.Map<List<ReleaseSpringCompressionDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ReleaseSpringCompression = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "releaseSpringCompression";
                        table.tableName = "整流罩星箭分离弹簧压缩数据记录表";
                        table.FiledDesc = filedMap["整流罩星箭分离弹簧压缩数据记录表"].filedValue;
                        table.FiledName = filedMap["整流罩星箭分离弹簧压缩数据记录表"].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ReleaseSpringCompression = new List<ReleaseSpringCompressionDto>();
                    }
                }
                if (tableNameArry[i] == "载荷支架组合体形位数据记录表")
                {
                    var data = (ObjectMapper.Map<List<LoadBracketDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.LoadBracket = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "loadBracket";
                        table.tableName = "载荷支架组合体形位数据记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.LoadBracket = new List<LoadBracketDto>();
                    }

                }
                if (tableNameArry[i] == "设计签署总装数据记录表")
                {
                    var data = (ObjectMapper.Map<List<DesignGeneralAssembleDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.DesignGeneralAssemble = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "designGeneralAssemble";
                        table.tableName = "设计签署总装数据记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.DesignGeneralAssemble = new List<DesignGeneralAssembleDto>();
                    }
                }
                if (tableNameArry[i] == "管路活门气密点检查记录表皂泡法")
                {
                    var data = (ObjectMapper.Map<List<SoapBubbleDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.SoapBubble = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "soapBubble";
                        table.tableName = "管路活门气密点检查记录表皂泡法";
                        table.FiledDesc = filedMap["管路活门气密点检查记录表皂泡法"].filedValue;
                        table.FiledName = filedMap["管路活门气密点检查记录表皂泡法"].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.SoapBubble = new List<SoapBubbleDto>();
                    }
                }
                if (tableNameArry[i] == "管路活门气密点检查记录表氦质谱法")
                {
                    var data = (ObjectMapper.Map<List<HeliumMassSpectrometryDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.HeliumMassSpectrometry = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "heliumMassSpectrometry";
                        table.tableName = "管路活门气密点检查记录表氦质谱法";
                        table.FiledDesc = filedMap["管路活门气密点检查记录表氦质谱法"].filedValue;
                        table.FiledName = filedMap["管路活门气密点检查记录表氦质谱法"].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.HeliumMassSpectrometry = new List<HeliumMassSpectrometryDto>();
                    }
                }
                if (tableNameArry[i] == "除了打保险防松外的总装直属件记录表")
                {
                    var data = (ObjectMapper.Map<List<FinalAssemblyPartsDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.FinalAssemblyParts = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "finalAssemblyParts";
                        table.tableName = "除了打保险防松外的总装直属件记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.FinalAssemblyParts = new List<FinalAssemblyPartsDto>();
                    }
                }
                if (tableNameArry[i] == "传感器安装测试记录情况统计记录表")
                {
                    var data = (ObjectMapper.Map<List<SensorInstallationDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.SensorInstallation = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "sensorInstallation";
                        table.tableName = "传感器安装测试记录情况统计记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.SensorInstallation = new List<SensorInstallationDto>();
                    }
                }
                if (tableNameArry[i] == "插头状态检查表")
                {
                    var data = (ObjectMapper.Map<List<PlugStatusDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.PlugStatus = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "plugStatus";
                        table.tableName = "插头状态检查表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.PlugStatus = new List<PlugStatusDto>();
                    }
                }
                if (tableNameArry[i] == "惯组安装记录表一")
                {
                    var data = (ObjectMapper.Map<List<FirstIMUInstallationDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.FirstIMUInstallation = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "firstIMUInstallation";
                        table.tableName = "惯组安装记录表一";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.FirstIMUInstallation = new List<FirstIMUInstallationDto>();
                    }
                }
                if (tableNameArry[i] == "惯组安装记录表二")
                {
                    var data = (ObjectMapper.Map<List<SecondIMUInstallationDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.SecondIMUInstallation = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "secondIMUInstallation";
                        table.tableName = "惯组安装记录表二";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.SecondIMUInstallation = new List<SecondIMUInstallationDto>();
                    }
                }
                if (tableNameArry[i] == "电缆高度测量记录表")
                {
                    var data = (ObjectMapper.Map<List<CableHeightDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.CableHeight = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "cableHeight";
                        table.tableName = "电缆高度测量记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.CableHeight = new List<CableHeightDto>();
                    }
                }
                if (tableNameArry[i] == "电缆剥线试验记录表低频")
                {
                    var data = (ObjectMapper.Map<List<LowFrequencyCableStrippingDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.LowFrequencyCableStripping = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "lowFrequencyCableStripping";
                        table.tableName = "电缆剥线试验记录表低频";
                        table.FiledDesc = filedMap["电缆剥线试验记录表低频"].filedValue;
                        table.FiledName = filedMap["电缆剥线试验记录表低频"].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.LowFrequencyCableStripping = new List<LowFrequencyCableStrippingDto>();
                    }
                }
                if (tableNameArry[i] == "压接实验测量记录表低频")
                {
                    var data = (ObjectMapper.Map<List<LowCrimpingExperimentDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.LowCrimpingExperiment = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "lowCrimpingExperiment";
                        table.tableName = "压接实验测量记录表低频";
                        table.FiledDesc = filedMap["压接实验测量记录表低频"].filedValue;
                        table.FiledName = filedMap["压接实验测量记录表低频"].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.LowCrimpingExperiment = new List<LowCrimpingExperimentDto>();
                    }
                }
                if (tableNameArry[i] == "电缆剥线试验记录表高频")
                {
                    var data = (ObjectMapper.Map<List<HighFrequencyCableStrippingDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.HighFrequencyCableStripping = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "highFrequencyCableStripping";
                        table.tableName = "电缆剥线试验记录表高频";
                        table.FiledDesc = filedMap["电缆剥线试验记录表高频"].filedValue;
                        table.FiledName = filedMap["电缆剥线试验记录表高频"].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.HighFrequencyCableStripping = new List<HighFrequencyCableStrippingDto>();
                    }
                }
                if (tableNameArry[i] == "仪器接收检查记录表")
                {
                    var data = (ObjectMapper.Map<List<InstrumentCheckDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InstrumentCheck = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "instrumentCheck";
                        table.tableName = "仪器接收检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InstrumentCheck = new List<InstrumentCheckDto>();
                    }
                }
                if (tableNameArry[i] == "电缆接收检查记录表")
                {
                    var data = (ObjectMapper.Map<List<CableReceivingInspectionDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.CableReceivingInspection = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "cableReceivingInspection";
                        table.tableName = "电缆接收检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.CableReceivingInspection = new List<CableReceivingInspectionDto>();
                    }
                }
                if (tableNameArry[i] == "箭地接口保护件检查记录表")
                {
                    var data = (ObjectMapper.Map<List<ArrowInterfaceProtectCheckDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ArrowInterfaceProtectCheck = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "arrowInterfaceProtectCheck";
                        table.tableName = "箭地接口保护件检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ArrowInterfaceProtectCheck = new List<ArrowInterfaceProtectCheckDto>();
                    }
                }
                if (tableNameArry[i] == "通用检查记录表")
                {
                    var data = (ObjectMapper.Map<List<InspectionRecordDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InspectionRecord = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "inspectionRecord";
                        table.tableName = "通用检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InspectionRecord = new List<InspectionRecordDto>();
                    }
                }
                if (tableNameArry[i] == "对接面形位记录表")
                {
                    var data = (ObjectMapper.Map<List<DockSurfaceMorphemeDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.DockSurfaceMorpheme = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "dockSurfaceMorpheme";
                        table.tableName = "对接面形位记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.DockSurfaceMorpheme = new List<DockSurfaceMorphemeDto>();
                    }
                }
                if (tableNameArry[i] == "整流罩锉修记录表")
                {
                    var data = (ObjectMapper.Map<List<FilingFileRepairDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.FilingFileRepair = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "filingFileRepair";
                        table.tableName = "整流罩锉修记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.FilingFileRepair = new List<FilingFileRepairDto>();
                    }
                }
                if (tableNameArry[i] == "整流罩安装后检查记录表")
                {
                    var data = (ObjectMapper.Map<List<CheckFairingAfterInstallationDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.CheckFairingAfterInstallation = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "checkFairingAfterInstallation";
                        table.tableName = "整流罩安装后检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.CheckFairingAfterInstallation = new List<CheckFairingAfterInstallationDto>();
                    }
                }
                if (tableNameArry[i] == "导管检查记录表")
                {
                    var data = (ObjectMapper.Map<List<CatheterizationDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.Catheterization = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "catheterization";
                        table.tableName = "导管检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.Catheterization = new List<CatheterizationDto>();
                    }
                }
                if (tableNameArry[i] == "管路上箭前吹除记录表")
                {
                    var data = (ObjectMapper.Map<List<BlowPipeArrowDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.BlowPipeArrow = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "blowPipeArrow";
                        table.tableName = "管路上箭前吹除记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.BlowPipeArrow = new List<BlowPipeArrowDto>();
                    }
                }
                if (tableNameArry[i] == "气封管流量测试记录表")
                {
                    var data = (ObjectMapper.Map<List<GasPipeTestDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.GasPipeTest = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "gasPipeTest";
                        table.tableName = "气封管流量测试记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.GasPipeTest = new List<GasPipeTestDto>();
                    }
                }
                if (tableNameArry[i] == "阀门气瓶过滤器流量计输送管金属软管等检查记录表")
                {
                    var data = (ObjectMapper.Map<List<ValvesGasInspectionDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ValvesGasInspection = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "valvesGasInspection";
                        table.tableName = "阀门、气瓶、过滤器、流量计、输送管、金属软管等检查记录表";
                        table.FiledDesc = filedMap["阀门气瓶过滤器流量计输送管金属软管等检查记录表"].filedValue;
                        table.FiledName = filedMap["阀门气瓶过滤器流量计输送管金属软管等检查记录表"].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ValvesGasInspection = new List<ValvesGasInspectionDto>();
                    }
                }
                if (tableNameArry[i] == "单机安装位置记录表")
                {
                    var data = (ObjectMapper.Map<List<InstallationLocationDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InstallationLocation = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "installationLocation";
                        table.tableName = "单机安装位置记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InstallationLocation = new List<InstallationLocationDto>();
                    }
                }
                if (tableNameArry[i] == "安装距离记录表")
                {
                    var data = (ObjectMapper.Map<List<InstallationDistanceDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InstallationDistance = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "installationDistance";
                        table.tableName = "安装距离记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InstallationDistance = new List<InstallationDistanceDto>();
                    }
                }
                if (tableNameArry[i] == "小导管卡箍间距测量表")
                {
                    var data = (ObjectMapper.Map<List<MeasurementSpacingConduitDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.MeasurementSpacingConduit = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "measurementSpacingConduit";
                        table.tableName = "小导管卡箍间距测量表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.MeasurementSpacingConduit = new List<MeasurementSpacingConduitDto>();
                    }
                }
                if (tableNameArry[i] == "未按要求施加力矩及未打保险防松记录表")
                {
                    var data = (ObjectMapper.Map<List<FailureAequiredLoosInsuranceDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.FailureAequiredLoosInsurance = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "failureAequiredLoosInsurance";
                        table.tableName = "未按要求施加力矩及未打保险防松记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.FailureAequiredLoosInsurance = new List<FailureAequiredLoosInsuranceDto>();
                    }
                }
                if (tableNameArry[i] == "分解重装记录表")
                {
                    var data = (ObjectMapper.Map<List<DisassemblyReassemblyDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.DisassemblyReassembly = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "disassemblyReassembly";
                        table.tableName = "分解重装记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.DisassemblyReassembly = new List<DisassemblyReassemblyDto>();
                    }
                }
                if (tableNameArry[i] == "配合七零三绝热记录表")
                {
                    var data = (ObjectMapper.Map<List<Insulation703Dto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.Insulation703 = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "insulation703";
                        table.tableName = "配合七零三绝热记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.Insulation703 = new List<Insulation703Dto>();
                    }
                }
                if (tableNameArry[i] == "绝热去除记录表")
                {
                    var data = (ObjectMapper.Map<List<AdiabaticRemovalDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.AdiabaticRemoval = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "adiabaticRemoval";
                        table.tableName = "绝热去除记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.AdiabaticRemoval = new List<AdiabaticRemovalDto>();
                    }
                }
                if (tableNameArry[i] == "连续拧紧环节力矩复校记录表")
                {
                    var data = (ObjectMapper.Map<List<CalibrationContinuousTorqueDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.CalibrationContinuousTorque = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "calibrationContinuousTorque";
                        table.tableName = "连续拧紧环节力矩复校记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.CalibrationContinuousTorque = new List<CalibrationContinuousTorqueDto>();
                    }
                }
                if (tableNameArry[i] == "管路垫块安装情况记录表")
                {
                    var data = (ObjectMapper.Map<List<InstallationPipeCushionDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InstallationPipeCushion = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "installationPipeCushion";
                        table.tableName = "管路垫块安装情况记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InstallationPipeCushion = new List<InstallationPipeCushionDto>();
                    }
                }
                if (tableNameArry[i] == "箭体结构防水记录表")
                {
                    var data = (ObjectMapper.Map<List<ArrowStructureWaterproofDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ArrowStructureWaterproof = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "arrowStructureWaterproof";
                        table.tableName = "箭体结构防水记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ArrowStructureWaterproof = new List<ArrowStructureWaterproofDto>();
                    }
                }
                if (tableNameArry[i] == "搭接线安装部位防水记录表")
                {
                    var data = (ObjectMapper.Map<List<WaterproofInstallationLapdDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.WaterproofInstallationLapd = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "waterproofInstallationLapd";
                        table.tableName = "搭接线安装部位防水记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.WaterproofInstallationLapd = new List<WaterproofInstallationLapdDto>();
                    }
                }
                if (tableNameArry[i] == "箭体称重时多装少装产品记录表")
                {
                    var data = (ObjectMapper.Map<List<ArrowScalageProductsDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ArrowScalageProducts = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "arrowScalageProducts";
                        table.tableName = "箭体称重时多装少装产品记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ArrowScalageProducts = new List<ArrowScalageProductsDto>();
                    }
                }
                if (tableNameArry[i] == "箭体称重记录表")
                {
                    var data = (ObjectMapper.Map<List<ArrowWeightDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ArrowWeight = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "arrowWeight";
                        table.tableName = "箭体称重记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ArrowWeight = new List<ArrowWeightDto>();
                    }
                }
                if (tableNameArry[i] == "总装零件称重记录表")
                {
                    var data = (ObjectMapper.Map<List<AssemnleweighingDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.Assemnleweighing = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "assemnleweighing";
                        table.tableName = "总装零件称重记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.Assemnleweighing = new List<AssemnleweighingDto>();
                    }
                }
                if (tableNameArry[i] == "阀门安装状态确认表")
                {
                    var data = (ObjectMapper.Map<List<ConfirmationStatusDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ConfirmationStatus = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "confirmationStatus";
                        table.tableName = "阀门安装状态确认表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ConfirmationStatus = new List<ConfirmationStatusDto>();
                    }
                }
                if (tableNameArry[i] == "传感器变换器对应关系确认记录表")
                {
                    var data = (ObjectMapper.Map<List<CorrespondingRelationshipDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.CorrespondingRelationship = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "correspondingRelationship";
                        table.tableName = "传感器变换器对应关系确认记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.CorrespondingRelationship = new List<CorrespondingRelationshipDto>();
                    }
                }
                if (tableNameArry[i] == "密封插头压接多媒体记录表")
                {
                    var data = (ObjectMapper.Map<List<CrimpingSealedPlugDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.CrimpingSealedPlug = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "crimpingSealedPlug";
                        table.tableName = "密封插头压接多媒体记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.CrimpingSealedPlug = new List<CrimpingSealedPlugDto>();
                    }
                }
                if (tableNameArry[i] == "气瓶组充放气速率记录表")
                {
                    var data = (ObjectMapper.Map<List<CylinderGroupDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.CylinderGroup = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "cylinderGroup";
                        table.tableName = "气瓶组充放气速率记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.CylinderGroup = new List<CylinderGroupDto>();
                    }
                }
                if (tableNameArry[i] == "气瓶压力测试记录表")
                {
                    var data = (ObjectMapper.Map<List<CylinderPressureTestDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.CylinderPressureTest = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "cylinderPressureTest";
                        table.tableName = "气瓶压力测试记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.CylinderPressureTest = new List<CylinderPressureTestDto>();
                    }
                }
                if (tableNameArry[i] == "干燥剂检查记录表")
                {
                    var data = (ObjectMapper.Map<List<DesiccantInspectionDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.DesiccantInspection = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "desiccantInspection";
                        table.tableName = "干燥剂检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.DesiccantInspection = new List<DesiccantInspectionDto>();
                    }
                }
                if (tableNameArry[i] == "低频压接实验测量记录表")
                {
                    var data = (ObjectMapper.Map<List<ExperimentalCrimpingDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ExperimentalCrimping = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "experimentalCrimping";
                        table.tableName = "低频压接实验测量记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ExperimentalCrimping = new List<ExperimentalCrimpingDto>();
                    }
                }
                if (tableNameArry[i] == "飞行质量质心皮重及参数记录表")
                {
                    var data = (ObjectMapper.Map<List<FlightMassCentroidTareWeightDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.FlightMassCentroidTareWeight = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "flightMassCentroidTareWeight";
                        table.tableName = "飞行质量质心皮重及参数记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.FlightMassCentroidTareWeight = new List<FlightMassCentroidTareWeightDto>();
                    }
                }
                if (tableNameArry[i] == "气封流量测试记录表")
                {
                    var data = (ObjectMapper.Map<List<GasSealFlowTestDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.GasSealFlowTest = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "gasSealFlowTest";
                        table.tableName = "气封流量测试记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.GasSealFlowTest = new List<GasSealFlowTestDto>();
                    }
                }
                if (tableNameArry[i] == "总装耗材称重记录表")
                {
                    var data = (ObjectMapper.Map<List<GeneralWeighingDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.GeneralWeighing = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "generalWeighing";
                        table.tableName = "总装耗材称重记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.GeneralWeighing = new List<GeneralWeighingDto>();
                    }
                }
                if (tableNameArry[i] == "高频压接点电阻及抗电强度检查记录表")
                {
                    var data = (ObjectMapper.Map<List<HighFrequencyVoltageDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.HighFrequencyVoltage = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "highFrequencyVoltage";
                        table.tableName = "高频压接点电阻及抗电强度检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.HighFrequencyVoltage = new List<HighFrequencyVoltageDto>();
                    }
                }
                if (tableNameArry[i] == "产品安装数量记录表")
                {
                    var data = (ObjectMapper.Map<List<InstallationQuantityDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InstallationQuantity = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "installationQuantity";
                        table.tableName = "产品安装数量记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InstallationQuantity = new List<InstallationQuantityDto>();
                    }
                }
                if (tableNameArry[i] == "接口检查记录表")
                {
                    var data = (ObjectMapper.Map<List<InterfaceCheckDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InterfaceCheck = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "interfaceCheck";
                        table.tableName = "接口检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InterfaceCheck = new List<InterfaceCheckDto>();
                    }
                }
                if (tableNameArry[i] == "岗位分工表")
                {
                    var data = (ObjectMapper.Map<List<JobDivisionDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.JobDivision = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "jobDivision";
                        table.tableName = "岗位分工表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.JobDivision = new List<JobDivisionDto>();
                    }
                }
                if (tableNameArry[i] == "随大部段交付产品明细表")
                {
                    var data = (ObjectMapper.Map<List<LargePartsDeliveryDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.LargePartsDelivery = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "largePartsDelivery";
                        table.tableName = "随大部段交付产品明细表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.LargePartsDelivery = new List<LargePartsDeliveryDto>();
                    }
                }
                if (tableNameArry[i] == "飞行质量质心设备调平数据记录表")
                {
                    var data = (ObjectMapper.Map<List<LevelingDataFlightDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.LevelingDataFlight = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "levelingDataFlight";
                        table.tableName = "飞行质量质心设备调平数据记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.LevelingDataFlight = new List<LevelingDataFlightDto>();
                    }
                }
                if (tableNameArry[i] == "液位传感器尺寸协调记录表")
                {
                    var data = (ObjectMapper.Map<List<LiquidLevelSensorDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.LiquidLevelSensor = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "liquidLevelSensor";
                        table.tableName = "液位传感器尺寸协调记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.LiquidLevelSensor = new List<LiquidLevelSensorDto>();
                    }
                }
                if (tableNameArry[i] == "产品安装确认表")
                {
                    var data = (ObjectMapper.Map<List<ProductInstallationConfirmationDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ProductInstallationConfirmation = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "productInstallationConfirmation";
                        table.tableName = "产品安装确认表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ProductInstallationConfirmation = new List<ProductInstallationConfirmationDto>();
                    }
                }
                if (tableNameArry[i] == "通用保护件检查记录表")
                {
                    var data = (ObjectMapper.Map<List<ProtectivePartsDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ProtectiveParts = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "protectiveParts";
                        table.tableName = "通用保护件检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ProtectiveParts = new List<ProtectivePartsDto>();
                    }
                }
                if (tableNameArry[i] == "象限标识检查记录表")
                {
                    var data = (ObjectMapper.Map<List<QuadrantCheckDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.QuadrantCheck = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "quadrantCheck";
                        table.tableName = "象限标识检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.QuadrantCheck = new List<QuadrantCheckDto>();
                    }
                }
                if (tableNameArry[i] == "通用接收检查记录表")
                {
                    var data = (ObjectMapper.Map<List<ReceivingInspectionRecordDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ReceivingInspectionRecord = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "receivingInspectionRecord";
                        table.tableName = "通用接收检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ReceivingInspectionRecord = new List<ReceivingInspectionRecordDto>();
                    }
                }
                if (tableNameArry[i] == "系统保压记录表")
                {
                    var data = (ObjectMapper.Map<List<SystemPressureMaintainingDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.SystemPressureMaintaining = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "systemPressureMaintaining";
                        table.tableName = "系统保压记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.SystemPressureMaintaining = new List<SystemPressureMaintainingDto>();
                    }
                }
                if (tableNameArry[i] == "电磁阀尾罩检查表")
                {
                    var data = (ObjectMapper.Map<List<TailCoverSolenoidDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.TailCoverSolenoid = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "tailCoverSolenoid";
                        table.tableName = "电磁阀尾罩检查表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.TailCoverSolenoid = new List<TailCoverSolenoidDto>();
                    }
                }
                if (tableNameArry[i] == "高频压接点抗拉强度检查记录表")
                {
                    var data = (ObjectMapper.Map<List<TensileStrengthHighDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.TensileStrengthHigh = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "tensileStrengthHigh";
                        table.tableName = "高频压接点抗拉强度检查记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.TensileStrengthHigh = new List<TensileStrengthHighDto>();
                    }
                }
                if (tableNameArry[i] == "横向质心测量记录表")
                {
                    var data = (ObjectMapper.Map<List<TransverseCentroidDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.TransverseCentroid = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "transverseCentroid";
                        table.tableName = "横向质心测量记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.TransverseCentroid = new List<TransverseCentroidDto>();
                    }
                }
                if (tableNameArry[i] == "阀门测试记录表一")
                {
                    var data = (ObjectMapper.Map<List<ValveTestDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ValveTest = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "valveTest";
                        table.tableName = "阀门测试记录表一";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ValveTest = new List<ValveTestDto>();
                    }
                }
                if (tableNameArry[i] == "阀门测试记录表二")
                {
                    var data = (ObjectMapper.Map<List<ValveTestSecDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ValveTestSec = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "valveTestSec";
                        table.tableName = "阀门测试记录表二";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ValveTestSec = new List<ValveTestSecDto>();
                    }
                }
                if (tableNameArry[i] == "阀门使用次数记录表")
                {
                    var data = (ObjectMapper.Map<List<ValveUsageTimesDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.ValveUsageTimes = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "valveUsageTimes";
                        table.tableName = "阀门使用次数记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.ValveUsageTimes = new List<ValveUsageTimesDto>();
                    }
                }
                if (tableNameArry[i] == "大部段称重记录表")
                {
                    var data = (ObjectMapper.Map<List<LargeSectionWeightDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.LargeSectionWeight = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "largeSectionWeight";
                        table.tableName = "大部段称重记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        table.Sort = data.First().Sort;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.LargeSectionWeight = new List<LargeSectionWeightDto>();
                    }
                }
                if (tableNameArry[i] == "电连接器插接多媒体记录表")
                {
                    var data = (ObjectMapper.Map<List<MultimediaElectricalConnectDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.MultimediaElectricalConnect = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "multimediaElectricalConnect";
                        table.tableName = "电连接器插接多媒体记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.MultimediaElectricalConnect = new List<MultimediaElectricalConnectDto>();
                    }
                }
                if (tableNameArry[i] == "仪器安装电缆余量多媒体记录表")
                {
                    var data = (ObjectMapper.Map<List<InstrumentCableAllowanceDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InstrumentCableAllowance = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "instrumentCableAllowance";
                        table.tableName = "仪器安装电缆余量多媒体记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InstrumentCableAllowance = new List<InstrumentCableAllowanceDto>();
                    }
                }
                if (tableNameArry[i] == "仪器安装分离钢索多媒体记录表")
                {
                    var data = (ObjectMapper.Map<List<InstrumentSeparationCableDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InstrumentSeparationCable = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "instrumentSeparationCable";
                        table.tableName = "仪器安装分离钢索多媒体记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InstrumentSeparationCable = new List<InstrumentSeparationCableDto>();
                    }
                }
                if (tableNameArry[i] == "仪器安装分离力测试多媒体记录表")
                {
                    var data = (ObjectMapper.Map<List<InstrumentSeparationForceTestDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InstrumentSeparationForceTest = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "instrumentSeparationForceTest";
                        table.tableName = "仪器安装分离力测试多媒体记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InstrumentSeparationForceTest = new List<InstrumentSeparationForceTestDto>();
                    }
                }
                if (tableNameArry[i] == "仪器安装力矩记录表")
                {
                    var data = (ObjectMapper.Map<List<InstrumentTorqueRecordDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.InstrumentTorqueRecord = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "instrumentTorqueRecord";
                        table.tableName = "仪器安装力矩记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.InstrumentTorqueRecord = new List<InstrumentTorqueRecordDto>();
                    }
                }
                if (tableNameArry[i] == "仪器插座安装多媒体记录表")
                {
                    var data = (ObjectMapper.Map<List<MultimediaSheetSocketDto>>(query)).OrderBy(d => d.SerialNum);
                    if (data.Count() > 0)
                    {
                        workStep.MultimediaSheetSocket = data.ToList();
                        TableNameDictionary table = new TableNameDictionary();
                        table.tablekey = "multimediaSheetSocket";
                        table.tableName = "仪器插座安装多媒体记录表";
                        table.FiledDesc = filedMap[table.tableName].filedValue;
                        table.FiledName = filedMap[table.tableName].filedKey;
                        tableNameDictionary.Add(table);
                    }
                    else
                    {
                        workStep.MultimediaSheetSocket = new List<MultimediaSheetSocketDto>();
                    }
                }
            }
        }
        /// <summary>
        /// 根据工序Id获取工序信息
        /// </summary>
        /// <param name = "processId" ></param>
        /// <returns></returns>
        public ProcessesEntityDto GetProcessesById(Guid processId)
        {
            var tempPro = ObjectMapper.Map<ProcessesEntityDto>(_processesEntityRepository.Get(processId));
            //var code = "";
            //if (tempPro.TechniqueEntityId != null)
            //{
            //    var tech = _techniqueEntityRepository.FirstOrDefault(tempPro.TechniqueEntityId);
            //    if (tech != null)
            //    {
            //        code = tech.TechniqueNumber;
            //    }
            //}
            string url = ConfigHelper.GetAppSetting("App", "GetAppUrl");
            if (tempPro.ProcessesExplain != null)
            {
                tempPro.ProcessesExplain = tempPro.ProcessesExplain.Replace("../", url + @"/");

                //tempPro.ProcessesExplain.Replace("src=\"", "src=\"" + url + @"/UploadFile/" + code + @"/");
            }
            return tempPro;
        }
        //public ProcessesEntity GetProcessesById(Guid processId)
        //{
        //    string url = ConfigHelper.GetAppSetting("App", "ServerRootAddress");
        //    var t = _processesEntityRepository.Get(processId);
        //    t.ProcessesExplain = t.ProcessesExplain.Replace("../", url + @"/");
        //    return t;
        //}
        /// <summary>
        /// 根据工步Id获取关联相关表
        /// </summary>
        /// <param name="workStepId">工步Id</param>
        /// <returns></returns>
        public WorkStepAndProcessDto GetWorkStepOut(Guid workStepId)
        {
            if (string.IsNullOrEmpty(workStepId.ToString()))
            {
                throw new UserFriendlyException("节点不可为空!");
            }
            var workStep = _workStepEntityRepository.GetAll().Where(d => d.Id == workStepId).First();
            WorkStepOutDto workDto = new WorkStepOutDto();
            workDto.Id = workStepId;
            workDto.TechniqueEntityId = workStep.TechniqueEntityId;
            workDto.ProcessesEntityId = workStep.ProcessesEntityId;
            workDto.OriginalWorkStepEntityId = workStep.OriginalWorkStepEntityId;
            workDto.WorkStepNumber = workStep.WorkStepNumber;
            workDto.WorkStepName = workStep.WorkStepName;
            workDto.WorkStepCharacteristic = workStep.WorkStepCharacteristic;
            string url = ConfigHelper.GetAppSetting("App", "GetAppUrl");
            if (!string.IsNullOrEmpty(workStep.WorkStepContent))
            {
                workDto.WorkStepContent = workStep.WorkStepContent.Replace("../", url + @"/");
            }
            if (string.IsNullOrEmpty(workStep.WorkDetails))
            {
                workDto.WorkDetails = (workStep.WorkStepName + "<br>" + workStep.WorkStepContent).Replace("../", url + @"/");
            }
            else
            {
                workDto.WorkDetails = workStep.WorkDetails;
            }
            workDto.WorkStepWorking = workStep.WorkStepWorking;
            List<TableNameDictionary> tableNameDictionary = new List<TableNameDictionary>();
            WorkStepJsonAnalysis(workDto, tableNameDictionary);
            tableNameDictionary = tableNameDictionary.OrderBy(d => d.Sort).ToList();
            WorkStepAndProcessDto workStepAndProcessDto = ObjectMapper.Map<WorkStepAndProcessDto>(_processesEntityRepository.Get(workDto.ProcessesEntityId));
            workStepAndProcessDto.workStepOut = workDto;
            workStepAndProcessDto.tableNameDictionary = tableNameDictionary;
            return workStepAndProcessDto;
        }


        /// <summary>
        /// 根据NodeId获取工序
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ProcessesDto GetProcessDataByNodeId(Guid id)
        {
            if (string.IsNullOrEmpty(id.ToString()))
            {
                throw new UserFriendlyException("节点不可为空!");
            }
            ProcessesDto processDto = new ProcessesDto();
            return processDto = ObjectMapper.Map<ProcessesDto>(_processesEntityRepository.GetAll().Where(d => d.TechniqueEntityId == id).FirstOrDefault());
        }
        /// <summary>
        /// 生成Pad端所需要的用户-角色-权限的Json流
        /// </summary>
        /// <returns></returns>
        public async Task<List<PadJurisdictionDto>> GetUserPermissions()
        {
            try
            {
                List<PadJurisdictionDto> dtoList = new List<PadJurisdictionDto>();

                //abp  获取 人员的角色 权限 典型的 rpac
                var roleUser = _roleRepository.GetAll().Where(d => d.DisplayName.Contains("Mes57")).Select(d => d.Id);
                var userIdList = _userRoleRepository.GetAll().Where(d => roleUser.Contains(d.RoleId)).Select(d => d.UserId).Distinct();
                var users = _userRepository.GetAll().Where(d => userIdList.Contains(d.Id));
                foreach (var item in users)
                {


                    PadJurisdictionDto dto = new PadJurisdictionDto();
                    dto.UserId = item.Id;
                    dto.UserName = item.UserName;
                    dto.Name = item.Surname + item.Name;
                    var ownUser = _sys_UserManageRepository.FirstOrDefault(d => d.UserId == item.Id);
                    //这里按照客户要求 如果 登录未查找到用户 或者该用户未登录 就默认123456为密码
                    if (ownUser == null)
                    {
                        dto.PlaintextPwd = "123456";
                    }
                    else
                    {
                        dto.PlaintextPwd = ownUser.PlaintextPwd;
                    }

                    var userOrs = _userOrganizationUnitRepository.GetAll().Where(d => d.UserId == dto.UserId);
                    List<OrganizationModel> organizations = new List<OrganizationModel>();
                    foreach (var organization in userOrs)
                    {
                        OrganizationModel model = new OrganizationModel();
                        model.OrganizationUnitId = organization.OrganizationUnitId;
                        model.OrganizationUnitDisplayName = _organizationUnitRepository.Get(organization.OrganizationUnitId).DisplayName;
                        organizations.Add(model);
                    }
                    dto.Organizations = organizations;
                    var roleList = _userRoleRepository.GetAll().Where(d => d.UserId == item.Id).Select(d => d.RoleId);
                    List<string> permissionList = new List<string>();
                    List<RoleModel> roleModes = new List<RoleModel>();
                    foreach (var roleId in roleList)
                    {
                        RoleModel roleModel = new RoleModel();
                        var roleTemp = await _roleRepository.GetAsync(roleId);
                        roleModel.DisplayName = roleTemp.DisplayName;
                        roleModel.RoleId = roleTemp.Id;
                        var tempLst = await GetGrantedPermissionsAsyncc(roleId);

                        permissionList.AddRange(tempLst);
                        roleModes.Add(roleModel);
                    }
                    dto.UserRoles = roleModes;
                    dto.Permissions = permissionList.Distinct().ToList();
                    dtoList.Add(dto);
                }

                return dtoList;
            }
            catch (Exception err)
            {
                return null;
            }

        }
        /// <summary>
        /// 根据roleId获取分配的权限
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public async Task<List<string>> GetGrantedPermissionsAsyncc(int roleId)
        {
            List<string> grantedList = new List<string>();
            var grantedPermissions = await _roleManager.GetGrantedPermissionsAsync(roleId);
            foreach (var item in grantedPermissions)
            {
                grantedList.Add(item.Name);
            }
            return grantedList;
        }
        /// <summary>
        /// 复制文件夹中文件到另一个文件夹的方法
        /// </summary>
        /// <param name="srcPath">源路径</param>
        /// <param name="aimPath">目标路径</param>
        private bool CopyDir(string srcPath, string aimPath)
        {
            try
            {
                // 检查目标目录是否以目录分割字符结束如果不是则添加
                if (aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
                {
                    aimPath += System.IO.Path.DirectorySeparatorChar;
                }
                // 判断目标目录是否存在如果不存在则新建
                if (!System.IO.Directory.Exists(aimPath))
                {
                    System.IO.Directory.CreateDirectory(aimPath);
                }
                // 得到源目录的文件列表，该里面是包含文件以及目录路径的一个数组
                // 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
                // string[] fileList = Directory.GetFiles（srcPath）；
                string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
                // 遍历所有的文件和目录
                foreach (string file in fileList)
                {
                    // 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
                    if (System.IO.Directory.Exists(file))
                    {
                        CopyDir(file, aimPath + System.IO.Path.GetFileName(file));
                    }
                    // 否则直接Copy文件
                    else
                    {
                        System.IO.File.Copy(file, aimPath + System.IO.Path.GetFileName(file), true);
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                //return false;
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// Pad发送文件，先生成Zip文件然后在发送
        /// </summary>
        /// <param name="precossId"></param>
        /// <param name="nodeLevel"></param>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="bopNodeId"></param>
        /// <param name="padId"></param>
        public ResultMessage PadSenFile(Guid? precossId, int nodeLevel, string ip, int port, Guid bopNodeId, string padId, string padName)
        {
            //先打包文件 然后发送给pad端
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                string nodePadId;
                string nodePadName;
                Guid? techId;//工艺文件id
                Guid bopId;//任务Id

                /*导出限制逻辑：（后续如何管控？？？分不同按钮）
                        1、一个节点导出工艺文件只能导出一次；
                        2、部套导出和工序导出不能并行*/
                if ((nodeLevel == 2) || (nodeLevel == 3) || (nodeLevel == 8))
                {
                    Guid guid = new Guid(precossId.Value.ToString());
                    FilesTransferAppService filesTransfer = new FilesTransferAppService(_operationHeartBeat);
                    string zipPathName = "";
                    if ((nodeLevel == 2) || (nodeLevel == 3))
                    {
                        var node = _bopNodeRepository.GetAll().Where(d => d.Id == bopNodeId).First();
                        nodePadId = node.PadId;
                        nodePadName = node.PadName;
                        techId = node.TechniqueEntityId;
                        bopId = node.BopDescId;
                        if (techId != Guid.Empty)
                        {
                            if (string.IsNullOrEmpty(nodePadId)) // || (!string.IsNullOrEmpty(nodePadId)) && (nodePadId== padId))
                            {
                                //节点导出，需要判断是否有 工序导出过
                                int count = _processesEntityRepository.Count(p => p.TechniqueEntityId == techId && p.PadId != null);
                                if (count == 0)
                                {
                                    zipPathName = ExportJsonPackage(bopNodeId, guid, nodeLevel);
                                    filesTransfer.SendFile(zipPathName, ip, port, bopNodeId, padId);
                                    //导出文件，修改状态
                                    node.PadId = padId;
                                    node.PadName = padName;
                                    node.IsExport = 1;
                                    node.ExportDate = DateTime.Now;
                                    _bopNodeRepository.Update(node);
                                    //修改任务状态为 已导出
                                    var bopDesc = _bopDescRepository.FirstOrDefault(c => c.Id == bopId);
                                    bopDesc.Status = (Status)3;
                                    _bopDescRepository.Update(bopDesc);
                                    _iOperationHistoryAppService.InsertOperationLog(node.BopDescId, 0, 5, node.NodeName + "导出工艺规程");
                                    //将树结构关联信息导入质量树结构中
                                    var data = ObjectMapper.Map<RbopDesc>(bopDesc);
                                    RbopDesc rbopDesc = new RbopDesc();
                                    if (_rBopDescRepository.FirstOrDefault(d => d.Id == data.Id) != null)
                                    {
                                        //  _rBopDescRepository.Delete(data.Id);
                                    }
                                    else
                                    {
                                        _rBopDescRepository.Insert(data);
                                    }

                                    var nodeData = _bopNodeRepository.GetAll().Where(d => d.BopDescId == bopDesc.Id);
                                    var rbopNode = ObjectMapper.Map<List<RbopNode>>(nodeData);
                                    foreach (var item in rbopNode)
                                    {
                                        if (_rBopNodeRepository.FirstOrDefault(d => d.Id == item.Id) != null)
                                        {
                                            continue;
                                        }
                                        _rBopNodeRepository.Insert(item);
                                    }
                                    var bopNodeIds = rbopNode.Select(d => d.Id).ToList();
                                    var rbopContent = ObjectMapper.Map<List<RbopContent>>(_bopContentRepository.GetAll().Where(d => bopNodeIds.Contains(d.BopNodeId)));
                                    foreach (var item in rbopContent)
                                    {
                                        if (_rbopContentRepository.FirstOrDefault(d => d.Id == item.Id) != null)
                                        {
                                            continue;
                                        }
                                        _rbopContentRepository.Insert(item);
                                    }
                                }
                                else
                                {
                                    resultMessage.code = 1;
                                    resultMessage.Message = "该工艺文件有过工序导出，不能再全本导出!";
                                    return resultMessage;
                                    //throw new UserFriendlyException("该工艺文件有过工序导出，不能再全本导出!");
                                }
                            }
                            else
                            {
                                resultMessage.code = 1;
                                resultMessage.Message = "该节点对应工艺文件已导入Pad：" + nodePadName;
                                return resultMessage;
                                //throw new UserFriendlyException("该节点对应工艺文件已导入Pad：" + nodePadName);
                            }
                        }
                        else
                        {
                            resultMessage.code = 1;
                            resultMessage.Message = "该节点无绑定工艺文件,无法导出!";
                            return resultMessage;
                            //throw new UserFriendlyException("该节点无绑定工艺文件,无法导出!");
                        }
                    }
                    else if (nodeLevel == 8)
                    {
                        //防错：一个节点导出工艺文件只能导出一次
                        var process = _processesEntityRepository.Get(guid);
                        nodePadId = process.PadId;
                        nodePadName = process.PadName;
                        techId = process.TechniqueEntityId;
                        if (string.IsNullOrEmpty(nodePadId))
                        {
                            //判断该工艺文件有没有过正本导出
                            int i = _bopNodeRepository.Count(p => p.TechniqueEntityId == techId && p.PadId != null);
                            if (i == 0)
                            {
                                zipPathName = ExportJsonPackage(bopNodeId, guid, nodeLevel);
                                filesTransfer.SendFile(zipPathName, ip, port, bopNodeId, padId);
                                //导出文件，修改状态
                                process.PadId = padId;
                                process.PadName = padName;
                                _processesEntityRepository.Update(process);
                                _iOperationHistoryAppService.InsertOperationLog(_bopNodeRepository.FirstOrDefaultAsync(d => d.TechniqueEntityId == techId).Result.BopDescId, 0, 5, process.ProcessesName + "导出工艺规程");
                            }
                            else
                            {
                                resultMessage.code = 1;
                                resultMessage.Message = "该工艺文件有过全本导出，不能再按工艺导出!";
                                return resultMessage;
                                //throw new UserFriendlyException("该工艺文件有过全本导出，不能再按工艺导出!");
                            }
                        }
                        else
                        {
                            resultMessage.code = 1;
                            resultMessage.Message = "该节点对应工艺文件已导入Pad：" + nodePadName;
                            return resultMessage;
                            //throw new UserFriendlyException("该节点对应工艺文件已导入Pad：" + nodePadName);
                        }
                    }
                }
                else
                {
                    resultMessage.code = 1;
                    resultMessage.Message = "该节点不能发送文件";
                    return resultMessage;
                    //throw new UserFriendlyException("该节点不能发送文件");
                }
                resultMessage.code = 0;
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }
        /// <summary>
        ///  取消PadId绑定
        /// </summary>
        /// <param name="nodeLevel">层级</param>
        /// <param name="bopNodeId">NodeId</param>
        /// <param name="precossId">工序Id</param>
        public void CancelPadId(int nodeLevel, Guid bopNodeId, Guid precossId)
        {
            if ((nodeLevel == 2) || (nodeLevel == 3))
            {
                var node = _bopNodeRepository.GetAll().Where(d => d.Id == bopNodeId).First();
                node.PadId = "";
                node.PadName = "";
                _bopNodeRepository.Update(node);

            }
            else if (nodeLevel == 8)
            {
                var process = _processesEntityRepository.Get(precossId);
                process.PadId = "";
                process.PadName = "";
                _processesEntityRepository.Update(process);
            }
            else
            {
                throw new UserFriendlyException("该节点暂无绑定信息!");
            }

        }

        /// <summary>
        /// 根据文件编号获取工艺文件详细信息(树节点)
        /// </summary>
        /// <param name="techniqueNumberStr">工艺文件编号名称</param>
        /// <returns></returns>
        public List<TreeClass> GetUnifyTechniqueById(string techniqueNumberStr)
        {
            List<TreeClass> treeNodes = new List<TreeClass>();
            var techniqueEntity = _techniqueEntityRepository.GetAll().Where(d => d.TechniqueNumber == techniqueNumberStr).FirstOrDefault();
            var bopNode = _bopNodeRepository.GetAll().FirstOrDefault(d => d.TechniqueEntityId == techniqueEntity.Id);

            if (techniqueEntity != null)
            {
                Guid techId = techniqueEntity.Id;
                //获取工序和工步的信息，并做相应的排序
                var processesList = _processesEntityRepository.GetAllIncluding(p => p.WorkStepEntities).Where(p => p.TechniqueEntityId == techId).OrderBy(n => n.ProcessesSequence).AsNoTracking();
                List<TreeClass> techList = new List<TreeClass>();
                TreeClass root = new TreeClass();
                root.Id = techniqueEntity.Id;
                root.NodeDrawingNo = "文件编号" + techniqueEntity.TechniqueNumber;
                root.NodeName = techniqueEntity.ProductCode;
                if (bopNode != null)
                {
                    root.IsRelation = 1;
                }
                else
                {
                    root.IsRelation = 0;
                }
                root.NodeLevel = 3;
                //循环遍历，往Node里面赋值
                foreach (var item in processesList)
                {
                    TreeClass tree = new TreeClass();
                    tree.Id = item.Id;
                    tree.ParentId = techniqueEntity.Id;
                    tree.NodeDrawingNo = "工序" + item.ProcessesSequence.ToString() + " ";
                    tree.NodeName = item.ProcessesName;
                    tree.IsRelation = 0;
                    tree.NodeLevel = 8;
                    var workStepData = item.WorkStepEntities.OrderBy(d => d.WorkStepNumber);
                    //查询工步
                    foreach (var witem in workStepData)
                    {
                        TreeClass wtree = new TreeClass();
                        wtree.Id = witem.Id;
                        wtree.ParentId = item.Id;
                        wtree.NodeDrawingNo = "工步" + item.ProcessesSequence.ToString();// + "-"+ witem.WorkStepNumber.ToString();
                        wtree.NodeName = witem.WorkStepNumber.ToString();//witem.WorkStepName  这个值数据库有问题
                        wtree.IsRelation = 0;
                        wtree.NodeLevel = 9;
                        tree.children.Add(wtree);
                    }
                    treeNodes.Add(tree);
                }
                root.children = treeNodes;
                techList.Add(root);
                return techList;
            }
            else
            {
                treeNodes.Clear();
                return treeNodes;
            }
        }
        /// <summary>
        ///  根据文件编号删除工艺规程接口（已关联发次的工艺规程不允许删除）
        /// </summary>
        /// <param name="id">工艺文件Guid</param>
        /// <returns></returns>
        public async Task<ResultMessage> DeleteTechniqueById(Guid id)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                var bopNode = _bopNodeRepository.FirstOrDefaultAsync(b => b.TechniqueEntityId == id).Result;
                if (bopNode != null)
                {
                    resultMessage.code = 1;
                    resultMessage.Message = "该工艺规程已关联工艺文件，若想删除请取消关联后再进行操作!";
                    return resultMessage;
                    //throw new UserFriendlyException("该工艺规程已关联工艺文件，若想删除请取消关联后再进行操作!");
                }
                else
                {
                    await _techniqueEntityRepository.DeleteAsync(d => d.Id == id);
                    await _processesEntityRepository.DeleteAsync(d => d.TechniqueEntityId == id);
                    await _workStepEntityRepository.DeleteAsync(d => d.TechniqueEntityId == id);
                }
                resultMessage.code = 0;
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }
        /// <summary>
        /// 根据NodeId回更接收状态
        /// </summary>
        /// <param name="nodeId"></param>
        /// <returns></returns>
        public bool UpdateReturnStatus(Guid nodeId, Guid techId)
        {
            //pad 回传时 回填库中数据
            var node = _bopNodeRepository.FirstOrDefault(d => d.Id == nodeId);
            var rnode = _rBopNodeRepository.FirstOrDefault(d => d.Id == nodeId);
            if (node != null)
            {
                node.IsReturn = 1;
                node.ReturnDate = DateTime.Now;
                _bopNodeRepository.Update(node);
                if (rnode != null)
                {
                    rnode.ProcessCode = node.ProcessCode;
                    rnode.IsReturn = 1;
                    rnode.RtechniqueEntityId = techId;
                    rnode.ReturnDate = node.ReturnDate;
                    //新增行，解决PAD回传登录验证问题
                    rnode.PadName = node.PadName;
                    _rBopNodeRepository.Update(rnode);
                    _iOperationHistoryAppService.InsertOperationLog(rnode.RbopDescId, 1, 10, rnode.NodeName + "已回传" + rnode.PadName, rnode.PadName == null ? "a" : node.PadName);
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        //初始化动态表格数据 表头名称 -表头英文描述 返回前台
        private void InitFiledNodeMap(Dictionary<string, FiledNodeMap> filedMap)
        {
            filedMap.Add("装入件明细", new FiledNodeMap(new List<string> { "代号", "名称", "数量", "备注" }, new List<string> { "code", "name", "number", "remark" }));
            filedMap.Add("制造资源", new FiledNodeMap(new List<string> { "类型", "ERPID", "代号或规格", "名称", "备注", "鉴定类别", "标准号", "是否必选" }, new List<string> { "type", "erpId", "specsCode", "name", "remark", "identifyType", "standardNumber", "isRequired" }));
            filedMap.Add("视频", new FiledNodeMap(new List<string> { "视频文件", "文件名" }, new List<string> { "videoFile", "fileName" }));
            filedMap.Add("通用总装数据记录表", new FiledNodeMap(
                new List<string> { "序号", "名称", "项目", "设计要求", "工艺要求", "实测值", "所用工具编号", "温度", "湿度", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
                new List<string> { "serialNum", "firstDrawingName", "recordElement", "designerDemand", "processorDemand", "firstMeasuredValues", "toolUsed", "temperature", "humidity", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
            ));
            filedMap.Add("通用记录表", new FiledNodeMap(
               new List<string> { "序号", "图号", "名称", "记录项目", "记录要求", "实测值", "确认结果", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
               new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "recordElement", "recordRequire", "firstMeasuredValues", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
           ));
            filedMap.Add("胶液配比情况记录表", new FiledNodeMap(
               new List<string> { "序号", "胶液名称", "记录元素", "实际情况", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
               new List<string> { "serialNum", "firstDrawingName", "recordItem", "measuredActual", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
           ));
            filedMap.Add("舱口盖开闭记录表", new FiledNodeMap(
              new List<string> { "序号", "图号", "壳段名称", "产品编号", "舱口盖位置或象限", "打开/关闭", "实测力矩", "所用力矩扳手编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
              new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "productNum", "recordLocation", "recordItem", "firstMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("进箱舱登记表", new FiledNodeMap(
             new List<string> { "序号", "型号", "图号", "名称", "工作事项", "进箱时间", "进箱携带物品", "携带物品数量", "出箱确认", "操作者", "操作者操作时间", "互检者", "互检者操作时间" },
             new List<string> { "serialNum", "model", "fisrtDrawingNum", "firstDrawingName", "recordStatus", "remarks", "recordRequire", "recordMainopoint", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData" }
           ));
            filedMap.Add("具有证明书的主要零件记录表", new FiledNodeMap(
              new List<string> { "序号", "图号", "名称", "零件编号", "合格证号编号", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
              new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "secondDrawingNum", "certificate", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
           ));
            filedMap.Add("力矩记录表", new FiledNodeMap(
              new List<string> { "序号", "零件1", "零件2", "设计要求_拧紧值N.m", "工艺要求_拧紧值N.m", "实测值N.m", "所用工具编号", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
              new List<string> { "serialNum", "fisrtDrawingNum", "secondDrawingNum", "designerDemand", "processorDemand", "firstMeasuredValues", "toolUsed", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
           ));
            filedMap.Add("通用多媒体记录表", new FiledNodeMap(
              new List<string> { "序号", "项目", "部位", "拍照(摄像)", "拍照(影像)编号", "确认结果", "操作者", "操作者操作时间", "互检者", "互检者操作时间" },
              new List<string> { "serialNum", "fisrtDrawingNum", "recordLocation", "recordRequire", "photoNo", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData" }
           ));
            filedMap.Add("通用力矩复校记录表", new FiledNodeMap(
              new List<string> { "序号", "零件1", "零件2", "复测力矩N.m", "工艺力矩N.m", "恢复力矩N.m", "力矩扳手编号", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
              new List<string> { "serialNum", "fisrtDrawingNum", "secondDrawingNum", "firstMeasuredValues", "processorDemand", "secondMeasuredValues", "toolUsed", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
           ));
            filedMap.Add("质量控制记录表", new FiledNodeMap(
              new List<string> { "项目", "操作者", "操作者日期", "互检", "互检日期", "检验员", "检验员日期" },
              new List<string> { "serialNum", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
           ));
            filedMap.Add("电缆插头防水防热记录表", new FiledNodeMap(
             new List<string> { "序号", "电缆/仪器代号", "插头代号", "实施情况", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间", "备注" },
             new List<string> { "serialNum", "fisrtDrawingNum", "secondDrawingNum", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData", "remarks" }
           ));
            filedMap.Add("波纹管变形记录表", new FiledNodeMap(
            new List<string> { "序号", "波纹管", "所属管路", "管路编号", "装配初始压缩量方向", "允许值", "安装前", "安装后", "变形量", "所用工具编号", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordLocation", "fisrtDrawingNum", "productNum", "recordElement", "designerDemand", "firstMeasuredValues", "secondMeasuredValues", "thirdMeasuredValues", "toolUsed", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("电连接器插接记录表", new FiledNodeMap(
            new List<string> { "序号", "所属仪器代号", "插头座代号", "插接照片", "防松照片", "防水照片", "防热照片", "操作者", "互检者", "检验员", "确认人" },
            new List<string> { "serialNum", "fisrtDrawingNum", "recordLocation", "photoNo", "secondPhotoNo", "thirdPhotoNo", "fourthPhotoNo", "firstOperator", "secondOperator", "thirdOperator", "fourthOperator" }
          ));
            filedMap.Add("舱口盖开闭测试记录表", new FiledNodeMap(
            new List<string> { "序号", "所属部段", "舱口盖名称", "记录位置", "是否能正常开关", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间", "备注" },
            new List<string> { "serialNum", "parentProductName", "firstDrawingName", "recordLocation", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData", "remarks" }
          ));
            filedMap.Add("产品接地状态检查记录表", new FiledNodeMap(
            new List<string> { "序号", "图号", "名称", "编号", "接地状态", "产品端搭接电阻（mΩ）", "等电位端搭接电阻（mΩ）", "所用仪器编号", "温度", "湿度", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "productNum", "firstConfirmResult", "firstMeasuredValues", "secondMeasuredValues", "toolUsed", "temperature", "humidity", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("强制检验点记录表", new FiledNodeMap(
            new List<string> { "序号", "项目", "设计要求", "实测结果", "是否合格", "照片编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间", "工艺员", "工艺员操作时间", "设计员", "设计员操作时间" },
            new List<string> { "serialNum", "recordElement", "designerDemand", "firstMeasuredValues", "firstConfirmResult", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData", "fourthOperator", "fourthOperatorData", "fifthOperator", "fifthOperatorData" }
          ));
            filedMap.Add("自动关闭口盖检查记录表", new FiledNodeMap(
            new List<string> { "序号", "口盖位置", "部段图号", "口盖名称", "检查确认项", "是否合格", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "firstDrawingName", "fisrtDrawingNum", "recordLocation", "recordItem", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("伺服机构工艺拉杆长度记录表", new FiledNodeMap(
            new List<string> { "序号", "项目", "名称", "要求长度（mm）", "实测长度（mm）", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordElement", "firstDrawingName", "designerDemand", "firstMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("状态检查表", new FiledNodeMap(
            new List<string> { "序号", "确认项目", "确认结果", "部门", "确认者", "确认者操作时间" },
            new List<string> { "serialNum", "recordElement", "firstConfirmResult", "recordRequire", "firstOperator", "firstOperatorData" }
          ));
            filedMap.Add("问题记录表", new FiledNodeMap(
            new List<string> { "序号", "名称", "记录项目", "问题记录", "解决措施", "多媒体", "备注" },
            new List<string> { "serialNum", "firstDrawingName", "recordElement", "abnormalRecord", "measuredActual", "photoNo", "remarks" }
          ));
            filedMap.Add("爆索尺寸测量记录表", new FiledNodeMap(
            new List<string> { "序号", "总长（mm）", "记录位置", "扁平（mm）", "宽度（mm）", "所用仪器编号", "温度", "湿度" },
            new List<string> { "serialNum", "thirdMeasuredValues", "recordLocation", "firstMeasuredValues", "secondMeasuredValues", "toolUsed", "temperature", "humidity" }
          ));
            filedMap.Add("整流罩星箭分离弹簧压缩数据记录表", new FiledNodeMap(
           new List<string> { "序号", "所属部段", "安装位置", "零件编号", "弹簧自由长度H0（mm）", "弹簧的工作载荷P2（N）", "压缩后长度L要求", "压缩后弹簧总长（mm）", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
           new List<string> { "serialNum", "parentProductName", "recordLocation", "productNum", "firstMeasuredValues", "secondMeasuredValues", "thirdMeasuredValues", "fourthMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("载荷支架组合体形位数据记录表", new FiledNodeMap(
            new List<string> { "序号", "名称", "单位", "测量值", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordItem", "recordRequire", "firstMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("设计签署总装数据记录表", new FiledNodeMap(
            new List<string> { "序号", "名称", "项目", "设计要求", "工艺要求", "实测值", "所用工具编号", "温度", "湿度", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间", "设计员", "设计员操作时间" },
            new List<string> { "serialNum", "firstDrawingName", "recordElement", "designerDemand", "processorDemand", "firstMeasuredValues", "toolUsed", "Temperature", "Humidity", "Remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData", "fourthOperator", "fourthOperatorData" }
          ));
            filedMap.Add("管路活门气密点检查记录表皂泡法", new FiledNodeMap(
            new List<string> { "序号", "系统名称", "测点前管路图号", "测点后管路图号", "检查压力(MPa)", "检查方法", "设计要求值Pa*m3/s", "工艺要求值", "检查结果", "备注" },
            new List<string> { "serialNum", "parentProductNum", "fisrtDrawingNum", "secondDrawingNum", "recordRequire", "recordElement", "designerDemand", "processorDemand", "firstMeasuredValues", "remarks" }
          ));
            filedMap.Add("管路活门气密点检查记录表氦质谱法", new FiledNodeMap(
            new List<string> { "序号", "系统名称", "测点前管路图号", "测点后管路图号", "检查压力(MPa)", "检查方法", "设计要求值Pa*m3/s", "工艺要求值", "检查点输出Pa•m3/s", "检查点漏率Pa•m3/s", "所用工具编号", "比对漏孔漏率Pa•m3/s", "E6_比对装置输出Pa•m3/s", "大气本体Pa•m3/s", "温度", "湿度", "备注" },
            new List<string> { "serialNum", "parentProductNum", "fisrtDrawingNum", "secondDrawingNum", "recordRequire", "recordElement", "designerDemand", "processorDemand", "firstMeasuredValues", "secondMeasuredValues", "toolUsed", "thirdMeasuredValues", "fourthMeasuredValues", "atmPressure", "temperature", "humidity", "remarks" }
          ));
            filedMap.Add("除了打保险防松外的总装直属件记录表", new FiledNodeMap(
            new List<string> { "序号", "零件1", "零件2", "安装位置", "紧固件材料及规格", "拧紧力矩要求（N·m）", "实际力矩施加值", "防松方式", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "secondDrawingNum", "parentProductName", "recordMainopoint", "designerDemand", "firstMeasuredValues", "measuredActual", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("传感器安装测试记录情况统计记录表", new FiledNodeMap(
            new List<string> { "序号", "图号", "名称", "状态", "传感器代号", "传感器名称", "参数代号", "导通检查点", "测试仪器1", "导通要求阻值", "实测阻值1", "绝缘检查点", "测试仪器2", "绝缘要求阻值", "实测阻值2", "所用数字三用表编号", "所用指针三用表编号", "所用温湿度计编号", "温度", "湿度", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "parentProductNum", "parentProductName", "recordStatus", "fisrtDrawingNum", "firstDrawingName", "recordLocation", "recordElement", "recordRequire", "designerDemand", "firstMeasuredValues", "recordItem", "recordMainopoint", "processorDemand", "secondMeasuredValues", "toolUsed", "secondToolUsed", "thirdToolUsed", "temperature", "humidity", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("插头状态检查表", new FiledNodeMap(
            new List<string> { "序号", "所属仪器/支架", "参数代号", "产品状态", "检查状态", "检查结果", "多媒体", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间", "备注" },
            new List<string> { "serialNum", "fisrtDrawingNum", "recordLocation", "recordStatus", "recordRequire", "firstConfirmResult", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData", "remarks" }
          ));
            filedMap.Add("惯组安装记录表一", new FiledNodeMap(
            new List<string> { "序号", "图号", "记录点", "间隙值", "导电胶带层数", "所用赛尺编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "recordLocation", "firstMeasuredValues", "secondMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("惯组安装记录表二", new FiledNodeMap(
            new List<string> { "序号", "图号", "记录要求", "实测值", "所用赛尺编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "recordItem", "firstMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("电缆高度测量记录表", new FiledNodeMap(
            new List<string> { "序号", "电缆束位置", "中间框位置（自前端面）", "电缆高度（靠I象限）", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordLocation", "firstMeasuredValues", "secondMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("电缆剥线试验记录表低频", new FiledNodeMap(
            new List<string> { "序号", "导线编号", "剥线长度1精确到0.5mm", "检查导线绝缘层切除后的外观情况", "多媒体（两端皆要拍照）", "测量工具编号", "剥线钳编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordLocation", "firstMeasuredValues", "firstConfirmResult", "photoNo", "toolUsed", "secondToolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("压接实验测量记录表低频", new FiledNodeMap(
            new List<string> { "序号", "图号", "记录要求", "设计要求", "实测值", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "recordItem", "designerDemand", "firstMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("电缆剥线试验记录表高频", new FiledNodeMap(
            new List<string> { "序号", "图号", "输出接口点号", "记录项目", "实测值", "检查结果", "多媒体", "剥线钳编号", "测量工具编号", "记录人", "记录人操作时间", "确认人", "确认人操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "recordLocation", "recordItem", "secondMeasuredValues", "firstConfirmResult", "photoNo", "secondToolUsed", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData" }
          ));
            filedMap.Add("仪器接收检查记录表", new FiledNodeMap(
            new List<string> { "序号", "所属仪器（支架）代号", "插头（座）代号", "外观检查", "电连接器检查", "合格证检查", "零件编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "recordLocation", "firstConfirmResult", "secondConfirmResult", "thirdConfirmResult", "firstMeasuredValues", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("电缆接收检查记录表", new FiledNodeMap(
            new List<string> { "序号", "电缆代号", "参数代号", "整体外观良好、证件齐全", "插头（座）正常、代号一致、插针无歪斜", "减振垫检查", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordLocation", "fisrtDrawingNum", "firstConfirmResult", "secondConfirmResult", "thirdConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("箭地接口保护件检查记录表", new FiledNodeMap(
            new List<string> { "序号", "安装位置", "堵盖规格/图号", "安装要求", "检查结果", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordLocation", "recordMainopoint", "recordRequire", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("通用检查记录表", new FiledNodeMap(
            new List<string> { "序号", "项目", "位置", "记录项目", "检查结果", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "parentProductName", "recordLocation", "recordItem", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("对接面形位记录表", new FiledNodeMap(
            new List<string> { "序号", "所属部段", "记录项目", "位置", "实测值", "所用工具编号", "温度", "湿度", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "parentProductName", "recordElement", "recordLocation", "firstMeasuredValues", "toolUsed", "temperature", "humidity", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("整流罩锉修记录表", new FiledNodeMap(
            new List<string> { "序号", "图号", "锉修过的安装孔记录" },
            new List<string> { "serialNum", "fisrtDrawingNum", "measuredActual" }
          ));
            filedMap.Add("整流罩安装后检查记录表", new FiledNodeMap(
            new List<string> { "序号", "检查项目", "确认结果", "问题记录", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "firstDrawingName", "firstConfirmResult", "measuredActual", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("导管检查记录表", new FiledNodeMap(
            new List<string> { "序号", "图号", "问题记录", "缺陷照片", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间", "设计员", "设计员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "measuredActual", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData", "fourthOperator", "fourthOperatorData" }
          ));
            filedMap.Add("管路上箭前吹除记录表", new FiledNodeMap(
            new List<string> { "序号", "图号", "吹除压力/Mpa", "吹除时间/min", "吹除确认", "绸布照片", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "firstMeasuredValues", "secondMeasuredValues", "firstConfirmResult", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("气封管流量测试记录表", new FiledNodeMap(
            new List<string> { "序号", "入口压力", "气源", "图号", "正向流量测量值", "正向流量校准值", "反向流量测量值", "反向流量校准值", "温度", "湿度", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "processorDemand", "recordRequire", "fisrtDrawingNum", "firstMeasuredValues", "secondMeasuredValues", "thirdMeasuredValues", "fourthMeasuredValues", "temperature", "humidity", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("阀门气瓶过滤器流量计输送管金属软管等检查记录表", new FiledNodeMap(
            new List<string> { "序号", "图号", "名称", "零件编号", "检查状态", "检查项目", "检查结果", "缺陷照片", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "productNum", "recordStatus", "recordElement", "firstConfirmResult", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("单机安装位置记录表", new FiledNodeMap(
            new List<string> { "序号", "阀门/过滤器", "安装位置", "零件编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "recordLocation", "productNum", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("安装距离记录表", new FiledNodeMap(
            new List<string> { "序号", "记录项目", "记录位置", "安装要求", "图号", "实际安装测量值", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordElement", "recordLocation", "recordRequire", "fisrtDrawingNum", "firstMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("小导管卡箍间距测量表", new FiledNodeMap(
            new List<string> { "序号", "管路图号", "数量", "距离/mm", "多媒体", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "recordMainopoint", "firstMeasuredValues", "photoNo", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("未按要求施加力矩及未打保险防松记录表", new FiledNodeMap(
            new List<string> { "序号", "记录项目", "安装位置", "紧固件材料及规格", "拧紧力矩要求N.m", "实际力矩施加情况", "未按要求施加力矩原因/防松方式", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordElement", "recordLocation", "recordMainopoint", "processorDemand", "firstMeasuredValues", "measuredActual", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("分解重装记录表", new FiledNodeMap(
            new List<string> { "序号", "时间", "原因", "部位", "更换或返修情况", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordMainopoint", "recordRequire", "fisrtDrawingNum", "measuredActual", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("配合七零三绝热记录表", new FiledNodeMap(
            new List<string> { "序号", "绝热部位", "位置", "数量", "是否完成", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "firstDrawingName", "parentProductName", "recordMainopoint", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("绝热去除记录表", new FiledNodeMap(
            new List<string> { "序号", "所在部位", "局部去除要求", "实际去除情况照片", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "parentProductName", "recordRequire", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("连续拧紧环节力矩复校记录表", new FiledNodeMap(
            new List<string> { "序号", "零件1", "工艺值1N.m", "复校值1N.m", "零件2", "工艺值2N.m", "复校值2N.m", "零件3", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "processorDemand", "firstMeasuredValues", "secondDrawingNum", "designerDemand", "secondMeasuredValues", "recordLocation", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("管路垫块安装情况记录表", new FiledNodeMap(
            new List<string> { "序号", "管路图号", "卡箍位置", "垫块安装情况", "螺钉规格", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "fisrtDrawingNum", "recordLocation", "measuredActual", "recordMainopoint", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("箭体结构防水记录表", new FiledNodeMap(
            new List<string> { "序号", "记录项目", "所属部段", "仪器代号", "操作要求", "确认结果", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
            new List<string> { "serialNum", "recordElement", "parentProductName", "fisrtDrawingNum", "designerDemand", "firstConfirmResult", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
          ));
            filedMap.Add("搭接线安装部位防水记录表", new FiledNodeMap(
            new List<string> { "序号", "位置", "记录对象", "操作要求", "数量", "是否封堵", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间", "备注" },
            new List<string> { "serialNum", "parentProductName", "recordElement", "designerDemand", "firstMeasuredValues", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData", "remarks" }
          ));
            filedMap.Add("总装零件称重记录表", new FiledNodeMap(
             new List<string> { "序号", "图号", "产品名称", "数量", "单件质量(g)", "总质量（g）", "设备编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "recordRequire", "firstMeasuredValues", "secondMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("总装耗材称重记录表", new FiledNodeMap(
             new List<string> { "序号", "技术条件", "名称", "领取重量(g)", "剩余重量(g)", "丢弃重量(g)", "上箭重量(g)", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "firstMeasuredValues", "secondMeasuredValues", "thirdMeasuredValues", "fourthMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("箭体称重记录表", new FiledNodeMap(
             new List<string> { "序号", "所属部段", "记录项目", "记录要求", "实测值", "出厂/飞行状态", "温度", "湿度", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "parentProductName", "recordElement", "recordRequire", "firstMeasuredValues", "recordStatus", "temperature", "humidity", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("箭体称重时多装少装产品记录表", new FiledNodeMap(
             new List<string> { "序号", "名称", "代号", "是否多装", "数量", "质量（Kg）" },
             new List<string> { "serialNum", "firstDrawingName", "fisrtDrawingNum", "firstConfirmResult", "firstMeasuredValues", "secondMeasuredValues" }
             ));
            filedMap.Add("飞行质量质心设备调平数据记录表", new FiledNodeMap(
             new List<string> { "序号", "记录项目", "传感器读数参考值", "传感器读数实际值" },
             new List<string> { "serialNum", "recordElement", "designerDemand", "firstMeasuredValues" }
             ));
            filedMap.Add("飞行质量质心皮重及参数记录表", new FiledNodeMap(
             new List<string> { "序号", "记录项目", "记录元素", "实测值" },
             new List<string> { "serialNum", "recordElement", "recordItem", "firstMeasuredValues" }
             ));
            filedMap.Add("横向质心测量记录表", new FiledNodeMap(
             new List<string> { "序号", "位置", "后支点称重", "后支点有效", "前支点称重", "前支点有效" },
             new List<string> { "serialNum", "recordLocation", "firstMeasuredValues", "secondMeasuredValues", "thirdMeasuredValues", "fourthMeasuredValues" }
             ));
            filedMap.Add("大部段称重记录表", new FiledNodeMap(
             new List<string> { "序号", "称重项目", "重量（Kg）", "所用工具编号", "温度", "湿度", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "recordElement", "firstMeasuredValues", "toolUsed", "temperature", "humidity", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("产品安装确认表", new FiledNodeMap(
             new List<string> { "序号", "检查项目", "检查情况", "检查结果", "备注" },
             new List<string> { "serialNum", "recordElement", "processorDemand", "measuredActual", "remarks" }
             ));
            filedMap.Add("阀门安装状态确认表", new FiledNodeMap(
             new List<string> { "序号", "图号", "编号", "名称", "确认项目", "实际状态", "备注" },
             new List<string> { "serialNum", "fisrtDrawingNum", "productNum", "firstDrawingName", "recordElement", "firstConfirmResult", "remarks" }
             ));
            filedMap.Add("通用接收检查记录表", new FiledNodeMap(
             new List<string> { "序号", "记录项目", "记录要求", "检查结果", "多媒体", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "recordElement", "recordRequire", "measuredActual", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("通用保护件检查记录表", new FiledNodeMap(
             new List<string> { "序号", "名称", "颜色", "数量", "安装位置", "检查情况", "问题记录", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "firstDrawingName", "recordStatus", "recordRequire", "recordLocation", "firstConfirmResult", "measuredActual", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("接口检查记录表", new FiledNodeMap(
             new List<string> { "序号", "代号", "位置", "检查情况", "问题记录", "多媒体", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "fisrtDrawingNum", "recordLocation", "firstConfirmResult", "measuredActual", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("象限标识检查记录表", new FiledNodeMap(
             new List<string> { "序号", "位置", "数量", "检查要求", "检查情况", "备注" },
             new List<string> { "serialNum", "recordLocation", "firstMeasuredValues", "recordRequire", "firstConfirmResult", "remarks" }
             ));
            filedMap.Add("干燥剂检查记录表", new FiledNodeMap(
             new List<string> { "序号", "记录项目", "干燥剂颜色", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "recordElement", "measuredActual", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("随大部段交付产品明细表", new FiledNodeMap(
             new List<string> { "序号", "图号", "名称", "数量", "是否正常", "备注" },
             new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "designerDemand", "firstConfirmResult", "remarks" }
             ));
            filedMap.Add("气瓶组充放气速率记录表", new FiledNodeMap(
             new List<string> { "序号", "开始时间", "结束时间", "时间要求值", "结束实测值", "速率", "所用工具编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "firstMeasuredValues", "secondMeasuredValues", "designerDemand", "thirdMeasuredValues", "fourthMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("系统保压记录表", new FiledNodeMap(
             new List<string> { "序号", "检查部位", "检查状态", "压力要求值（MPa）", "压力实测值（MPa）", "压降要求值（MPa）", "压降实测值（MPa）", "温度", "湿度", "所用工具编号" },
             new List<string> { "serialNum", "firstDrawingName", "recordStatus", "designerDemand", "firstMeasuredValues", "recordRequire", "secondMeasuredValues", "temperature", "humidity", "toolUsed" }
             ));
            filedMap.Add("气瓶压力测试记录表", new FiledNodeMap(
             new List<string> { "序号", "气瓶名称", "设计要求值", "实测值", "所用工具编号", "备注" },
             new List<string> { "serialNum", "firstDrawingName", "designerDemand", "firstMeasuredValues", "toolUsed", "remarks" }
             ));
            filedMap.Add("阀门使用次数记录表", new FiledNodeMap(
             new List<string> { "序号", "名称/代号", "产品编号", "允许使用次数", "试验项目", "动作次数", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "fisrtDrawingNum", "productNum", "designerDemand", "recordStatus", "firstMeasuredValues", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("阀门测试记录表一", new FiledNodeMap(
             new List<string> { "序号", "图号", "名称/代号", "测试项目", "测试要求", "产品编号", "测试状态", "实测值", "温度", "湿度", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "recordElement", "recordRequire", "productNum", "recordStatus", "firstMeasuredValues", "temperature", "humidity", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("气封流量测试记录表", new FiledNodeMap(
             new List<string> { "序号", "检测位置", "要求流量（g/s）", "测量值", "校准后（m3/h）", "所用工具编号", "温度", "湿度", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "firstDrawingName", "designerDemand", "firstMeasuredValues", "thirdMeasuredValues", "toolUsed", "temperature", "humidity", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("阀门测试记录表二", new FiledNodeMap(
             new List<string> { "序号", "图号", "名称/代号", "测试项目", "测试要求", "产品编号", "测试状态", "第一次", "第二次", "温度", "湿度", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "recordElement", "recordRequire", "productNum", "recordStatus", "firstMeasuredValues", "secondMeasuredValues", "temperature", "humidity", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("电磁阀尾罩检查表", new FiledNodeMap(
             new List<string> { "序号", "图号", "参数代号", "箭上位置", "尾罩是否松动", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "fisrtDrawingNum", "recordRequire", "recordLocation", "firstConfirmResult", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("传感器变换器对应关系确认记录表", new FiledNodeMap(
             new List<string> { "序号", "电缆束1", "变换器插头座", "变换器代号", "变换器编号", "电缆束2", "传感器插头座", "传感器代号", "传感器编号", "是否对应", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "parentProductNum", "fisrtDrawingNum", "recordLocation", "recordStatus", "parentProductName", "secondDrawingNum", "recordRequire", "recordMainopoint", "firstConfirmResult", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("产品安装数量记录表", new FiledNodeMap(
             new List<string> { "序号", "项目", "使用数量", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "recordElement", "firstMeasuredValues", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));

            filedMap.Add("液位传感器尺寸协调记录表", new FiledNodeMap(
             new List<string> { "序号", "测量项目", "理论值(mm)", "实测值(mm)", "误差(mm)", "所用工具编号", "温度", "湿度", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "recordElement", "designerDemand", "firstMeasuredValues", "secondMeasuredValues", "toolUsed", "temperature", "humidity", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("密封插头压接多媒体记录表", new FiledNodeMap(
             new List<string> { "序号", "参数代号", "传感器代号", "箱内低温密封插头压接点", "输出接口点号", "插接照片", "备注", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间", "设计员", "设计员操作时间" },
             new List<string> { "serialNum", "parentProductNum", "fisrtDrawingNum", "recordLocation", "recordMainopoint", "photoNo", "remarks", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData", "fourthOperator", "fourthOperatorData" }
             ));
            filedMap.Add("岗位分工表", new FiledNodeMap(
             new List<string> { "序号", "岗位分工", "工作地点", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间", "确认人", "确认人操作时间" },
             new List<string> { "serialNum", "firstMeasuredValues", "measuredActual", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData", "fourthOperator", "fourthOperatorData" }
             ));
            filedMap.Add("低频压接实验测量记录表", new FiledNodeMap(
             new List<string> { "序号", "中间接头型", "拉脱力检查", "实测值1", "压接电阻检查", "实测值2", "抗电强度检查", "实测值3", "压接钳编号", "微欧计编号", "高阻表编号", "测力计编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "recordLocation", "recordRequire", "firstMeasuredValues", "recordStatus", "secondMeasuredValues", "recordMainopoint", "thirdMeasuredValues", "toolUsed", "secondToolUsed", "thirdToolUsed", "recordItem", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));

            filedMap.Add("高频压接点电阻及抗电强度检查记录表", new FiledNodeMap(
             new List<string> { "序号", "编号", "外导体压接电阻要求", "实测值1(mΩ)", "内导体压接电阻要求", "实测值2(mΩ)", "内导体抗电强度检查", "实测值3(mΩ)", "压接钳编号", "微欧计编号", "高阻表编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "recordLocation", "recordRequire", "firstMeasuredValues", "recordStatus", "secondMeasuredValues", "recordMainopoint", "thirdMeasuredValues", "toolUsed", "secondToolUsed", "thirdToolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));

            filedMap.Add("高频压接点抗拉强度检查记录表", new FiledNodeMap(
             new List<string> { "序号", "外导体拉脱要求", "实测值1(mΩ)", "内导体拉脱力要求", "实测值2", "拉脱力测试仪编号", "操作者", "操作者操作时间", "互检者", "互检者操作时间", "检验员", "检验员操作时间" },
             new List<string> { "serialNum", "recordRequire", "firstMeasuredValues", "recordStatus", "secondMeasuredValues", "toolUsed", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));

            filedMap.Add("电连接器插接多媒体记录表", new FiledNodeMap(
            new List<string> { "序号", "零件1图号/代号", "所属部段名称", "产品编号", "参数代号", "照片1", "照片2", "照片3", "照片4", "操作者", "操作者日期", "互检", "互检日期", "检验员", "检验员日期" },
            new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "productNum", "paramCode", "photoNo", "secondPhotoNo", "thirdPhotoNo", "fourthPhotoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
            ));
            filedMap.Add("仪器安装电缆余量多媒体记录表", new FiledNodeMap(
             new List<string> { "序号", "零件1图号/代号", "所属部段名称", "产品编号", "参数代号", "实测值1", "照片", "操作者", "操作者日期", "互检", "互检日期", "检验员", "检验员日期" },
             new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "productNum", "paramCode", "firstMeasuredValues", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("仪器安装分离钢索多媒体记录表", new FiledNodeMap(
             new List<string> { "序号", "零件1图号/代号", "所属部段名称", "产品编号", "参数代号", "实测值1", "照片", "操作者", "操作者日期", "互检", "互检日期", "检验员", "检验员日期" },
             new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "productNum", "paramCode", "firstMeasuredValues", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("仪器安装分离力测试多媒体记录表", new FiledNodeMap(
             new List<string> { "序号", "零件1图号/代号", "所属部段名称", "产品编号", "参数代号", "实测值1", "照片", "操作者", "操作者日期", "互检", "互检日期", "检验员", "检验员日期" },
             new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "productNum", "paramCode", "firstMeasuredValues", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("仪器安装力矩记录表", new FiledNodeMap(
             new List<string> { "序号", "零件1图号/代号", "所属部段名称", "产品编号", "参数代号", "所用工具编号", "设计要求", "工艺要求", "备注", "实测值1", "操作者", "操作者日期", "互检", "互检日期", "检验员", "检验员日期" },
             new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "productNum", "paramCode", "toolUsed", "designerDemand", "processorDemand", "remarks", "firstMeasuredValues", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
            filedMap.Add("仪器插座安装多媒体记录表", new FiledNodeMap(
             new List<string> { "序号", "零件1图号/代号", "所属部段名称", "产品编号", "参数代号", "实测值1", "照片", "操作者", "操作者日期", "互检", "互检日期", "检验员", "检验员日期" },
             new List<string> { "serialNum", "fisrtDrawingNum", "firstDrawingName", "productNum", "paramCode", "firstMeasuredValues", "photoNo", "firstOperator", "firstOperatorData", "secondOperator", "secondOperatorData", "thirdOperator", "thirdOperatorData" }
             ));
        }

        /// <summary>
        /// 拆分工步混杂的信息获取组合的Png
        /// </summary>
        /// <param name="imageStr"></param>
        /// <returns></returns>
        private string GetImageStr(string imageStr)
        {
            int startIndex = 0;
            string keyWord = "png";
            int index = 0;
            List<string> strArray = new List<string>();
            while ((index = imageStr.IndexOf(keyWord, index)) != -1)
            {
                string itemStr = imageStr.Substring(startIndex, index + keyWord.Length - startIndex);
                startIndex = index + keyWord.Length;
                index = index + keyWord.Length;
                strArray.Add(itemStr);
            }
            string combineStr = "";
            foreach (var item in strArray)
            {
                var imgStr = item.LastIndexOf("/");
                combineStr = combineStr + "," + item.Substring(imgStr + 1);
            }
            if (combineStr != "")
            {
                return combineStr.Substring(1);
            }
            else
            {
                return "";
            }

        }
        /// <summary>
        ///获取所有表名称
        /// </summary>
        /// <returns></returns>
        public List<string> LoadTableName()
        {
            Common.TableMapConfig tableMapConfig = new Common.TableMapConfig();
            Dictionary<string, FiledNodeMap> filedMap = tableMapConfig.InitFiledNodeMap();
            return filedMap.Keys.ToList();
        }
        /// <summary>
        /// 获取新增动态表信息
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public TableNameDictionary GetTableDetails(string table)
        {
            Common.TableMapConfig tableMapConfig = new Common.TableMapConfig();
            TableNameDictionary dic = new TableNameDictionary();
            Dictionary<string, FiledNodeMap> filedMap = tableMapConfig.InitFiledNodeMap();
            if (filedMap.ContainsKey(table))
            {
                dic.tablekey = filedMap[table].filedNodeDto;
                dic.tableName = table;
                dic.FiledDesc = filedMap[table].filedValue;
                dic.FiledName = filedMap[table].filedKey;
            }
            return dic;
        }
        /// <summary>
        ///删除单个表格
        /// </summary>
        /// <param name="workStepId"></param>
        /// <param name="tableName"></param>
        public ResultMessage DeleteWorkTable(Guid workStepId, string tableName)
        {
            //工艺规程变更 根据表格名称先从库中看是否能获取 如果存在 则删除 
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                var temp = _workStepEntityRepository.Get(workStepId);
                var tempPro = _processesEntityRepository.Get(temp.ProcessesEntityId);
                bool check = false;//检测是否删除  记录日志
                if (tableName == "装入件明细")
                {
                    var loadList = _loadPieceRepository.GetAll().Where(d => d.WorkStepEntityId == workStepId).ToList();
                    if (loadList.Count > 0)
                    {
                        foreach (var item in loadList)
                        {
                            _loadPieceRepository.Delete(item);
                        }
                        check = true;
                    }

                    //_iOperationHistoryAppService.InsertOperationLogNew(temp.TechniqueEntityId, OperationHistory.BusinessTypes.Bop变更管理, OperationHistory.OperationTypes.删除表, "【删除表】" + ": 工序" + tempPro.ProcessesSequence.ToString() + "工步" + temp.WorkStepNumber.ToString() + "删除" + tableName);
                }
                if (tableName == "制造资源")
                {
                    var loadList = _makeResourcesEntityRepository.GetAll().Where(d => d.WorkStepEntityId == workStepId).ToList();
                    if (loadList.Count > 0)
                    {
                        foreach (var item in loadList)
                        {
                            _makeResourcesEntityRepository.Delete(item);
                        }
                        check = true;
                    }

                    // _iOperationHistoryAppService.InsertOperationLogNew(temp.TechniqueEntityId, OperationHistory.BusinessTypes.Bop变更管理, OperationHistory.OperationTypes.删除表, "【删除表】" + ": 工序" + tempPro.ProcessesSequence.ToString() + "工步" + temp.WorkStepNumber.ToString() + "删除" + tableName);
                }
                if (tableName == "视频")
                {
                    var loadList = _videoEntityRepository.GetAll().Where(d => d.WorkStepEntityId == workStepId).ToList();
                    if (loadList.Count > 0)
                    {
                        foreach (var item in loadList)
                        {
                            _videoEntityRepository.Delete(item);
                        }
                        check = true;
                    }
                }
                //删除动态表格
                var fromTable = _tableBaseEntity.GetAllIncluding(a => a.RecordRequirements, b => b.InspectionSignature, c => c.MeasuredResult, d => d.Environment, e => e.MultiMedia).Where(d => d.WorkStepEntityId == workStepId && d.FormName == tableName).ToList();
                if (fromTable.Count > 0)
                {
                    foreach (var item in fromTable)
                    {
                        _tableBaseEntity.Delete(item);
                    }
                    check = true;
                }
                if (check)
                {
                    _iOperationHistoryAppService.InsertOperationLogNew(temp.TechniqueEntityId, OperationHistory.BusinessTypes.Bop变更管理, OperationHistory.OperationTypes.删除表, "【删除表】" + ": 工序" + tempPro.ProcessesSequence.ToString() + "工步" + temp.WorkStepNumber.ToString() + "删除" + tableName);
                }
                resultMessage.code = 0;
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }

        /// <summary>
        /// 删除某工步下的关联表
        /// </summary>
        /// <param name="workId"></param>
        /// <param name="tableName"></param>
        /// <param name="bappId"></param>
        public void DeleteOneTable(Guid workId, string tableName, Guid bappId)
        {
            //根据表格id删除表格
            var query = _tableBaseEntity.GetAll().Where(d => d.WorkStepEntityId == workId && d.FormName == tableName);
            if (query.Count() > 0)
            {
                foreach (var item in query)
                {
                    _tableBaseEntity.Delete(item);
                }
                _iOperationHistoryAppService.InsertOperationLog(bappId, 4, 18, _workStepEntityRepository.Get(workId).WorkStepName + "删除" + tableName);
            }
        }
        /// <summary>
        /// 上传
        /// 
        /// </summary>
        /// <param name="uploadedFile"></param>
        /// <param name="workStepId"></param>
        /// <returns></returns>
        public async Task UploadPicPreviewAsync(IFormFile uploadedFile, Guid workStepId)
        {
            try
            {
                if (uploadedFile != null)
                {
                    var formFileName = uploadedFile.FileName;
                    if (!new[] { ".png", ".jpg", ".bmp" }.Any((item) => formFileName.EndsWith(item)))
                    {
                        throw new AbpValidationException("您上传的文件格式必须为png、jpg、bmp中的一种");
                    }
                    var workStep = _workStepEntityRepository.Get(workStepId);
                    var techId = workStep.TechniqueEntityId;
                    var tech = _techniqueEntityRepository.Get(techId);
                    //文件保存的路径(应用的工作目录+文件夹相对路径);
                    string fileSavePath = Environment.CurrentDirectory + "/wwwroot/" + tech.TechniqueNumber;
                    if (!Directory.Exists(fileSavePath))
                    {
                        Directory.CreateDirectory(fileSavePath);
                    }
                    string filePath = Path.Combine(fileSavePath, formFileName);

                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        uploadedFile.CopyTo(fileStream);
                        fileStream.Flush();
                    }
                    workStep.WorkStepContent = "< img width=\"650\" height=\"417\" src=\"../../tech/" + tech.TechniqueNumber + "/" + formFileName + "\" border=\"0\"><p>" + formFileName + "</p >";
                    await _workStepEntityRepository.UpdateAsync(workStep);
                }
                else
                {
                    throw new UserFriendlyException("文件不能为空");
                }
            }
            catch (Exception ex)
            {
                throw new UserFriendlyException("文件上传失败，原因" + ex.Message);
            }
        }
        /// <summary>
        /// 删除图片
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public async Task DeleteImage(Guid guid, string fileName)
        {
            var workStep = _workStepEntityRepository.Get(guid);
            var techId = workStep.TechniqueEntityId;
            var tech = _techniqueEntityRepository.Get(techId);
            string fileSavePath = Environment.CurrentDirectory + "/wwwroot/" + tech.TechniqueNumber;
            string filePath = Path.Combine(fileSavePath, fileName);
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            //删除图片  具体看数据格式 
            if (workStep.WorkStepContent != null && workStep.WorkStepContent.Contains(fileName))
            {
                int fileIndex = workStep.WorkStepContent.IndexOf(fileName);
                var prefixIndexStr = workStep.WorkStepContent.Substring(0, fileIndex);
                var prefixIndex = prefixIndexStr.LastIndexOf("<");
                var prefixStr = prefixIndexStr.Substring(0, prefixIndex);
                var suffix = workStep.WorkStepContent.Substring(fileIndex, workStep.WorkStepContent.Length - fileIndex);
                int i = suffix.IndexOf(">", suffix.IndexOf(">", suffix.IndexOf(">") + 1) + 1);
                var suffixStr = suffix.Substring(i + 1);
                workStep.WorkStepContent = prefixStr + suffixStr;
                await _workStepEntityRepository.UpdateAsync(workStep);
            }
        }
        /// <summary>
        /// 检验装入件明细是否已配套
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public async Task<bool> CheckLoadPiece(Guid guid)
        {
            int count = await _storeStockContentRepsitory.CountAsync(d => d.LoadDetailsId == guid);
            if (count > 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        /// <summary>
        /// 获取Bop树 Zip包
        /// </summary>
        /// <param name="input"></param>
        public ResultMessage GetBopBatchExportJson(BopExportInput input)
        {
            // 任务-节点-工序-工步
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                BopExportput bopExportput = new BopExportput();
                BopTreeJson bopTree = new BopTreeJson();
                long edtion = 0;
                bopTree = GetBopTreeJson(input.ModelId, input.LotNoId, ref edtion);
                //var bopDesc1= _bopDescRepository.GetAll().Where(d => d.ModelId == input.ModelId && d.LotNoId == input.LotNoId).FirstOrDefault();
                //input.TechIdList = _bopNodeRepository.GetAll().Where(d => d.BopDescId == bopDesc1.Id).Where(d => d.TechniqueEntityId != null).Select(d=>d.TechniqueEntityId).ToList();

                if (input.TechIdList == null)
                {
                    resultMessage.code = 1;
                    resultMessage.Message = "请先选择要导出的规程!";
                    return resultMessage;
                    //throw new UserFriendlyException("请先选择要导出的规程!");
                }
                if (bopTree != null)
                {
                    String DateStr = System.DateTime.Now.ToString("yyyyMMddHHmm");
                    var tempDesc = _bopDescRepository.FirstOrDefault(d => d.ModelId == input.ModelId && d.LotNoId == input.LotNoId);
                    string treePath = "../../Bop/BopTree/" + DateStr + "/" + tempDesc.Model + "_" + tempDesc.LotNo + "/";
                    if (!Directory.Exists(treePath))
                    {
                        Directory.CreateDirectory(treePath);
                    }
                    string treefp = treePath + tempDesc.Model + "_" + tempDesc.LotNo + ".json"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
                    if (File.Exists(treefp))  // 判断是否已有相同文件 
                    {
                        File.Delete(treefp);
                    }
                    var treeJson = Newtonsoft.Json.JsonConvert.SerializeObject(bopTree);
                    File.WriteAllText(treefp, treeJson);

                    //if (!Directory.Exists("../../ZIP/BopTree/" + tempDesc.Model + tempDesc.LotNo + "/"))
                    //{
                    //    Directory.CreateDirectory("../../ZIP/BopTree/" + tempDesc.Model + tempDesc.LotNo + "/");
                    //}
                    //string zipTreeName = "../../ZIP/BopTree/" + tempDesc.Model + tempDesc.LotNo + "/" + tempDesc.Model + tempDesc.LotNo + ".zip";
                    //if (File.Exists(zipTreeName))
                    //{
                    //    File.Delete(zipTreeName);
                    //}
                    //ZipFile.CreateFromDirectory(treePath, zipTreeName);
                    //规程数据
                    var tempData = (from tempTech in _techniqueEntityRepository.GetAll()
                                    join tempNode in _bopNodeRepository.GetAll() on tempTech.Id equals tempNode.TechniqueEntityId
                                    join tempBopdesc in _bopDescRepository.GetAll() on tempNode.BopDescId equals tempBopdesc.Id
                                    join ttempTech in input.TechIdList on tempTech.Id equals ttempTech
                                    where tempBopdesc.ModelId == input.ModelId && tempBopdesc.LotNoId == input.LotNoId && tempNode.BopExprot == false
                                    select new
                                    {
                                        Id = tempTech.Id,
                                        Model = tempBopdesc.Model,
                                        ModelName = tempBopdesc.ModelName,
                                        LotNo = tempBopdesc.LotNo,
                                        DrawingNo = tempBopdesc.DrawingNo,
                                        StageSign = tempBopdesc.StageSign,
                                        BopDescId = tempBopdesc.Id,
                                        BopNodeId = tempNode.Id,
                                        Technique = tempTech,
                                    }).ToList();
                    if (tempData.Count > 0)
                    {
                        //List<BopTaskOutDto> bopTasks = new List<BopTaskOutDto>();
                        for (int i = 0; i < tempData.Count; i++)
                        {
                            BopTaskOutDto bopTask = new BopTaskOutDto();
                            bopTask.Id = tempData[i].Id;
                            bopTask.Model = tempData[i].Model;
                            bopTask.ModelName = tempData[i].ModelName;
                            bopTask.LotNo = tempData[i].LotNo;
                            bopTask.DrawingNo = tempData[i].DrawingNo;
                            bopTask.StageSign = tempData[i].StageSign;
                            TechniqueOutDto technique = new TechniqueOutDto();
                            technique = ObjectMapper.Map<TechniqueOutDto>(tempData[i].Technique);
                            var processess = _processesEntityRepository.GetAll().Where(p => p.TechniqueEntityId == tempData[i].Technique.Id).OrderBy(p => p.ProcessesSequence).ToList();
                            technique.ProcessesListDto = ObjectMapper.Map<List<ProcessesOutDto>>(processess);
                            List<TableNameDictionary> tableNameDictionary = new List<TableNameDictionary>();
                            //封装工序数据
                            foreach (var item in technique.ProcessesListDto)
                            {
                                if (!string.IsNullOrEmpty(item.ProcessesExplain))
                                {
                                    item.ProcessesExplain = item.ProcessesExplain.Replace("../DownLoadFileRootPath/" + technique.TechniqueNumber + "/", "");
                                }
                                //封装工步数据
                                var workSteps = _workStepEntityRepository.GetAll().Where(p => p.ProcessesEntityId == item.Id).OrderBy(p => p.WorkStepNumber).ToList();
                                item.WorkStepListDto = ObjectMapper.Map<List<WorkStepOutDto>>(workSteps);
                                foreach (var workStep in item.WorkStepListDto)
                                {
                                    if (workStep.WorkStepContent != null)
                                    {
                                        workStep.WorkStepContent = workStep.WorkStepContent.Replace("../DownLoadFileRootPath/" + technique.TechniqueNumber + "/", "");// GetImageStr(workStep.WorkStepContent);
                                    }

                                    tableNameDictionary.Clear();
                                    WorkStepJsonAnalysis(workStep, tableNameDictionary);
                                }
                            }
                            technique.BopDescId = tempData[i].BopDescId;
                            technique.BopNodeId = tempData[i].BopNodeId;
                            var tempBopNode = _bopNodeRepository.Get(tempData[i].BopNodeId);
                            tempBopNode.BopExprot = true;
                            _bopNodeRepository.Update(tempBopNode);
                            bopTask.TechniqueTask = technique;

                            string path = "../../Bop/BopTree/" + DateStr + "/" + tempData[i].Model + "_" + tempData[i].LotNo + "/" + tempData[i].Technique.TechniqueNumber + "/" + tempData[i].Technique.TechniqueNumber + "/";
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }
                            string fp = path + tempData[i].Technique.TechniqueNumber + ".json"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
                            if (File.Exists(fp))  // 判断是否已有相同文件 
                            {
                                File.Delete(fp);
                            }
                            var listjson = Newtonsoft.Json.JsonConvert.SerializeObject(bopTask);
                            File.WriteAllText(fp, listjson);
                            string srcPatch = Environment.CurrentDirectory + "/wwwroot/DownLoadFileRootPath/" + tempData[i].Technique.TechniqueNumber + "/";
                            if (!Directory.Exists(srcPatch))
                            {
                                Directory.CreateDirectory(srcPatch);
                            }
                            if (CopyDir(srcPatch, path))
                            {
                                //string zipdir = "../../ZIP/BopTree/" + tempData[i].Model + tempData[i].LotNo+"/"+ tempData[i].Technique.TechniqueNumber + "/";
                                //if (!Directory.Exists(zipdir))
                                //{
                                //    Directory.CreateDirectory(zipdir);
                                //}
                                //string  zipPathName = zipdir + tempData[i].Technique.TechniqueNumber + ".zip";
                                //if (File.Exists(zipPathName))
                                //{
                                //    File.Delete(zipPathName);
                                //}
                                //ZipFile.CreateFromDirectory(path, zipPathName);
                            }
                            else
                            {
                                resultMessage.code = 1;
                                resultMessage.Message = "复制文件文件失败!";
                                return resultMessage;
                                //throw new UserFriendlyException("复制文件文件失败!");
                            }
                        }

                        string fileSavePath = Environment.CurrentDirectory + "/wwwroot/Zip/BopTree/" + DateStr + "/" + tempDesc.Model + "_" + tempDesc.LotNo + "/";
                        if (!Directory.Exists(fileSavePath))
                        {
                            Directory.CreateDirectory(fileSavePath);
                        }
                        string zipTreeName = fileSavePath + tempDesc.Model + "_" + tempDesc.LotNo + "_" + edtion.ToString() + ".zip";
                        if (File.Exists(zipTreeName))
                        {
                            File.Delete(zipTreeName);
                        }
                        //组装打包然后压缩
                        CompressMulti(new List<string> { treePath }, zipTreeName, true);
                        //ZipFile.CreateFromDirectory(treePath, zipTreeName);
                        resultMessage.code = 0;
                        resultMessage.Message = ConfigHelper.GetAppSetting("App", "GetAppUrl") + "/Zip/BopTree/" + DateStr + "/" + tempDesc.Model + "_" + tempDesc.LotNo + "/" + tempDesc.Model + "_" + tempDesc.LotNo + "_" + edtion.ToString() + ".zip";
                        _iOperationHistoryAppService.InsertOperationLogNew(tempDesc.Id, OperationHistory.BusinessTypes.导出数据包, OperationHistory.OperationTypes.批量导出规程, "【v" + edtion.ToString() + "】" + resultMessage.Message);
                        tempDesc.Status = (Status)3;
                        _bopDescRepository.Update(tempDesc);

                        #region 生成质量数据
                        var data = ObjectMapper.Map<RbopDesc>(tempDesc);
                        RbopDesc rbopDesc = new RbopDesc();
                        if (_rBopDescRepository.FirstOrDefault(d => d.Id == data.Id) != null)
                        {
                            //  _rBopDescRepository.Delete(data.Id);
                        }
                        else
                        {
                            _rBopDescRepository.Insert(data);
                        }

                        var nodeData = _bopNodeRepository.GetAll().Where(d => d.BopDescId == tempDesc.Id);
                        //打包后 生成质量树 相关数据  
                        var rNodeData = _rBopNodeRepository.GetAll().Where(d => d.RbopDescId == tempDesc.Id);
                        var rbopNode = ObjectMapper.Map<List<RbopNode>>(nodeData);
                        if (rNodeData != null)
                        {
                            var diffrNode = rNodeData.Select(d => d.Id).Except(nodeData.Select(d => d.Id)).ToList();
                            foreach (var item in rbopNode)
                            {
                                if (diffrNode.FindIndex(d => d == item.Id) != -1)
                                {
                                    _rBopNodeRepository.Delete(item);

                                }
                                else
                                {
                                    if (_rBopNodeRepository.FirstOrDefault(d => d.Id == item.Id) != null)
                                    {
                                        continue;
                                    }
                                    _rBopNodeRepository.Insert(item);
                                }
                            }
                        }
                        else
                        {
                            foreach (var item in rbopNode)
                            {
                                _rBopNodeRepository.Insert(item);
                            }
                        }
                        var bopNodeIds = rbopNode.Select(d => d.Id).ToList();
                        var rbopContent = ObjectMapper.Map<List<RbopContent>>(_bopContentRepository.GetAll().Where(d => bopNodeIds.Contains(d.BopNodeId)));
                        foreach (var item in rbopContent)
                        {
                            if (_rbopContentRepository.FirstOrDefault(d => d.Id == item.Id) != null)
                            {
                                continue;
                            }
                            _rbopContentRepository.Insert(item);
                        }
                        #endregion
                        return resultMessage;
                        //return ConfigHelper.GetAppSetting("App", "GetAppUrl") + "/Zip/BopTree/" + DateStr + "/" + tempDesc.Model + tempDesc.LotNo + "/" + tempDesc.Model + tempDesc.LotNo + ".zip";
                    }
                    else
                    {
                        resultMessage.code = 1;
                        resultMessage.Message = "未查找到匹配的Bop数据!";
                        return resultMessage;
                        //throw new UserFriendlyException("未查找到匹配的Bop数据!");

                    }
                }
                else
                {
                    resultMessage.code = 1;
                    resultMessage.Message = "未查找到匹配的Bop数据!";
                    return resultMessage;
                    //throw new UserFriendlyException("未查找到匹配的Bop数据!");
                }
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }
        /// <summary>
        /// 批量导出Json包调用
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public ResultMessage DownloadBopBatchExport(BopExportInput input)
        {
            ResultMessage filepath = GetBopBatchExportJson(input);
            //Create temporary copy of logs
            //FileInfo file = new FileInfo(filepath);

            // //Create the zip file
            // var zipFileDto = new FileDto("WebSiteBop.zip", MimeTypeNames.ApplicationZip);

            //using (var outputZipFileStream = new MemoryStream())
            //{
            //    using (var zipStream = new ZipArchive(outputZipFileStream, ZipArchiveMode.Create))
            //    {

            //        var entry = zipStream.CreateEntry(file.Name);
            //        using (var entryStream = entry.Open())
            //        {
            //            using (var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 0x1000, FileOptions.SequentialScan))
            //            {
            //                fs.CopyTo(entryStream);
            //                entryStream.Flush();
            //            }
            //        }
            //    }

            //    _tempFileCacheManager.SetFile(zipFileDto.FileToken, outputZipFileStream.ToArray());
            //}
            //return zipFileDto;
            return filepath;
        }

        /// <summary>
        ///获取BopTree
        /// </summary>
        /// <param name="modelId"></param>
        /// <param name="lotNoId"></param>
        /// <returns></returns>
        public BopTreeJson GetBopTreeJson(Guid modelId, Guid lotNoId, ref long edition)
        {
            BopTreeJson bopTree = new BopTreeJson();
            var bopDescTemp = _bopDescRepository.GetAll().Where(d => d.ModelId == modelId && d.LotNoId == lotNoId).FirstOrDefault();
            if (bopDescTemp != null)
            {
                bopTree.Model = bopDescTemp.Model;
                bopTree.LotNo = bopDescTemp.LotNo;
                bopTree.Id = bopDescTemp.Id;
                bopTree.ParentId = Guid.Empty;
                bopTree.NodeDrawingNo = bopDescTemp.DrawingNo;
                bopTree.NodeName = bopDescTemp.ModelName;
                bopTree.IsRelation = 0;
                bopTree.NodeLevel = 0;

                var temp = _treeVersionLogRepository.GetAll().Where(d => d.ModelId == modelId && d.LotNoId == lotNoId).Where(d => d.Type == 0).FirstOrDefault();
                if (temp == null)
                {
                    TreeVersionLog versionLog = new TreeVersionLog();
                    versionLog.ModelId = modelId;
                    versionLog.LotNoId = lotNoId;
                    versionLog.Version = 1;
                    _treeVersionLogRepository.Insert(versionLog);
                    bopTree.Version = 1;
                    edition = bopTree.Version;
                }
                else
                {
                    temp.Version = temp.Version + 1;
                    _treeVersionLogRepository.Update(temp);
                    bopTree.Version = temp.Version + 1;
                    edition = bopTree.Version;
                }
                LoadBopTreeChildNode(bopDescTemp.Id, bopTree);
                return bopTree;
            }
            else
            {
                return null;
            }

        }
        public BopTreeJson GetShootBopTreeJson(Guid modelId, Guid lotNoId, ref long edition)
        {
            BopTreeJson bopTree = new BopTreeJson();
            var bopDescTemp = _bopDescRepository.GetAll().Where(d => d.ModelId == modelId && d.LotNoId == lotNoId).FirstOrDefault();
            if (bopDescTemp != null)
            {
                bopTree.Model = bopDescTemp.Model;
                bopTree.LotNo = bopDescTemp.LotNo;
                bopTree.Id = bopDescTemp.Id;
                bopTree.ParentId = Guid.Empty;
                bopTree.NodeDrawingNo = bopDescTemp.DrawingNo;
                bopTree.NodeName = bopDescTemp.ModelName;
                bopTree.IsRelation = 0;
                bopTree.NodeLevel = 0;
                LoadBopTreeChildNode(bopDescTemp.Id, bopTree);
                return bopTree;
            }
            else
            {
                return null;
            }

        }
        //遍历树节点
        private void LoadBopTreeChildNode(Guid Id, BopTreeJson treeNodeDto)
        {
            var bopNodeList = _bopNodeRepository.GetAll().Where(c => c.ParentId == Id);
            //var list = ObjectMapper.Map<List<BopNodeDto>>(bopNodeList);
            foreach (var item in bopNodeList)
            {
                BopTreeJson tree = new BopTreeJson();
                tree.Id = item.Id;
                tree.ParentId = item.ParentId;
                tree.NodeDrawingNo = item.NodeDrawingNo;
                tree.NodeName = item.NodeName;
                if (item.TechniqueEntityId == null)
                {
                    tree.IsRelation = 0;
                }

                else
                {
                    tree.IsRelation = 1;
                    var tech = _techniqueEntityRepository.GetAll().FirstOrDefault(d => d.Id == item.TechniqueEntityId.Value);
                    tree.TechniqueEntityId = tech.Id;
                    tree.TechniqueNumber = _techniqueEntityRepository.Get(tech.Id).TechniqueNumber;
                }

                tree.NodeLevel = item.NodeLevel;   //NodeLevel;
                tree.ParentCode = item.ParentCode;
                tree.NodeCode = item.NodeCode;
                tree.IsLeaf = item.IsLeaf;
                tree.IsExport = item.IsExport;
                LoadBopTreeChildNode(item.Id, tree);
                //NodeLevel--;
                //递归结束的终点条件
                treeNodeDto.TreeList.Add(tree);
            }
        }
        protected static double NextDouble(double miniDouble, double maxiDouble)
        {
            Random random = new Random();
            double num = maxiDouble - miniDouble;
            if (num <= double.MaxValue)
            {
                var ran = random.NextDouble();
                var numRes = (ran * (double)num) + miniDouble;
                return numRes;
            }
            int RandNum = random.Next();
            if ((random.Next() % 2 == 0) ? true : false)
            {
                num = -num;
            }
            double num2 = num;
            num2 += 2147483646.0;
            num2 = num2 / 4294967293.0;
            return (num2 * (double)num) + miniDouble;

        }
        /// <summary>
        /// 图片批量上传
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ResultCommonJson<string>> OnPostUploadAsync(IFormFileCollection files, Guid NodeId)
        {
            ResultCommonJson<string> resultMessage = new ResultCommonJson<string>();
            //变更上传图片 先上传图片 然后修改数据
            if (files == null)
            {

                resultMessage.code = 1;
                resultMessage.Message = "请选择图片!";
                return resultMessage;
            }
            if (files.Count == 0)
            {
                resultMessage.code = 1;
                resultMessage.Message = "请选择图片!";
                return resultMessage;
            }
            List<IFormFile> formFiles = new List<IFormFile>();
            foreach (var file in files)
            {
                formFiles.Add(file);
            }
            //CommonImageInput common = new CommonImageInput();
            //common.files = formFiles;
            //common.NodeId = NodeId;
            try
            {
                CommonImageOutput output = new CommonImageOutput();
                List<ImageInfoTemp> infoTemps = new List<ImageInfoTemp>();
                if (files != null)
                {

                    var filePath = Environment.CurrentDirectory + "\\wwwroot\\ImageTmep\\";
                    string TechniqueNumber = "";
                    string fileSavePath = "";
                    var nodeWork = await _workStepEntityRepository.FirstOrDefaultAsync(d => d.Id == NodeId);
                    var nodePro = await _processesEntityRepository.FirstOrDefaultAsync(d => d.Id == NodeId);
                    int nodeType = 0; //判断图片是否存在的标志
                    if (nodePro != null)
                    {
                        nodeType = 1;
                        var techNum = await _techniqueEntityRepository.GetAsync(nodePro.TechniqueEntityId);
                        TechniqueNumber = techNum.TechniqueNumber;
                        //文件保存的路径(应用的工作目录+文件夹相对路径);
                        fileSavePath = filePath + TechniqueNumber + "/";
                        if (!Directory.Exists(fileSavePath))
                        {
                            Directory.CreateDirectory(fileSavePath);
                        }
                    }

                    if (nodeWork != null)
                    {
                        nodeType = 2;
                        var techNum = await _techniqueEntityRepository.GetAsync(nodeWork.TechniqueEntityId);
                        TechniqueNumber = techNum.TechniqueNumber;
                        //文件保存的路径(应用的工作目录+文件夹相对路径);
                        fileSavePath = filePath + TechniqueNumber + "/";
                        if (!Directory.Exists(fileSavePath))
                        {
                            Directory.CreateDirectory(fileSavePath);
                        }
                    }

                    if (nodeType != 0)
                    {
                        for (int i = 0; i < files.Count; i++)
                        {
                            //ImageInfoTemp infoTemp = new ImageInfoTemp();

                            var formFile = files[i];
                            string url = ConfigHelper.GetAppSetting("App", "GetAppUrl") + "/ImageTmep/";
                            if (formFile.Length > 0)
                            {

                                if (!new[] { ".png", ".jpg", ".bmp" }.Any((item) => formFile.FileName.ToLower().EndsWith(item)))
                                {
                                    throw new AbpValidationException("您上传的文件格式必须为png、jpg、bmp中的一种");
                                }
                                var fileFullPath = Path.Combine(fileSavePath, formFile.FileName);
                                using (var stream = System.IO.File.Create(fileFullPath))
                                {
                                    await formFile.CopyToAsync(stream);
                                    stream.Flush();
                                }
                                resultMessage.Data.Add(url + TechniqueNumber + "/" + formFile.FileName);
                                //infoTemp.FileName = formFile.FileName;
                                //infoTemp.IFormFile = files[i];
                                //infoTemp.Size = files[i].Length;
                                //infoTemp.FileUrl = url + formFile.FileName;
                                //infoTemps.Add(infoTemp);
                            }
                        }
                    }
                }
                output.ImageInfos = infoTemps;
                resultMessage.code = 0;
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = "文件上传失败，原因" + ex.Message;
                return resultMessage;

            }
        }


        public class photoList
        {

            public int Id { get; set; }
            public string Pname { get; set; }

            public string FileName { get; set; }
        }

        /// <summary>
        /// 图片批量上传
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ResultCommonJson<string>> SaveUploadPic(IFormFileCollection files, string photoList, Guid NodeId)
        {
            ResultCommonJson<string> resultMessage = new ResultCommonJson<string>();

            var photos = JsonConvert.DeserializeObject<List<photoList>>(photoList);

            var filePath = "";
            string TechniqueNumber = "";
            string fileSavePath = "";
            var nodeWork = await _workStepEntityRepository.FirstOrDefaultAsync(d => d.Id == NodeId);
            var nodePro = await _processesEntityRepository.FirstOrDefaultAsync(d => d.Id == NodeId);
            int nodeType = 0;
            if (nodePro != null)
            {
                nodeType = 1;
                var techNum = await _techniqueEntityRepository.GetAsync(nodePro.TechniqueEntityId);
                TechniqueNumber = techNum.TechniqueNumber;

                filePath = Environment.CurrentDirectory + "/wwwroot/DownLoadFileRootPath/" + TechniqueNumber + "/";
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }

            }
            if (nodeWork != null)
            {
                nodeType = 2;
                var techNum = await _techniqueEntityRepository.GetAsync(nodeWork.TechniqueEntityId);
                TechniqueNumber = techNum.TechniqueNumber;
                filePath = Environment.CurrentDirectory + "/wwwroot/DownLoadFileRootPath/" + TechniqueNumber + "/";
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
            }

            if (files == null)
            {

                resultMessage.code = 1;
                resultMessage.Message = "请选择图片!";
                return resultMessage;
            }
            //整体私立先拆分数据 然后 校验服务器是否存在该图片 不存在则上传
            if (files.Count == 0)
            {
                string workContentStr = "";
                if (nodeType == 2)
                {
                    var images = GetImageParms(NodeId);
                    if (images.Count > 0)
                    {
                        List<int> temp = new List<int>();
                        for (int i = 0; i < images.Count; i++)
                        {
                            temp.Add(i + 1);
                        }
                        for (int i = 0; i < photos.Count; i++)
                        {
                            if (temp.Contains(photos[i].Id))
                            {
                                var tempImage = images[photos[i].Id - 1];
                                string url = ConfigHelper.GetAppSetting("App", "GetAppUrl");
                                var src = tempImage.Src.Replace(url + @"/", "../");
                                workContentStr = workContentStr + "," + "<img width=" + tempImage.Width + " height=" + tempImage.Height + " src=" + src + " border=" + tempImage.Border + "><p>" + photos[i].Pname + "</p>";
                            }
                        }
                        if (workContentStr != "")
                        {
                            nodeWork.WorkStepContent = workContentStr.Replace(",", "");
                            await _workStepEntityRepository.UpdateAsync(nodeWork);
                        }
                        resultMessage.code = 0;
                        return resultMessage;
                    }
                    else
                    {
                        resultMessage.code = 1;
                        resultMessage.Message = "未查找到相关数据!";
                        return resultMessage;
                    }
                }
                else
                {
                    resultMessage.code = 1;
                    resultMessage.Message = "请选择图片!";
                    return resultMessage;
                }

            }

            List<IFormFile> formFiles = new List<IFormFile>();
            foreach (var file in files)
            {
                formFiles.Add(file);
            }
            try
            {
                CommonImageOutput output = new CommonImageOutput();
                List<ImageInfoTemp> infoTemps = new List<ImageInfoTemp>();
                if (files != null)
                {
                    if (nodeType != 0 && nodeType == 2)
                    {
                        //组装 工步 content 数据
                        string workContentStr = "";
                        var images = GetImageParms(NodeId);
                        if (images.Count > 0)
                        {
                            List<int> temp = new List<int>();
                            for (int i = 0; i < images.Count; i++)
                            {
                                temp.Add(i + 1);
                            }
                            for (int i = 0; i < photos.Count; i++)
                            {
                                if (temp.Contains(photos[i].Id))
                                {
                                    var formFileOne = formFiles.Where(d => d.FileName.StartsWith(photos[i].FileName.ToString())).FirstOrDefault();
                                    if (formFileOne != null)
                                    {
                                        if (!new[] { ".png", ".jpg", ".bmp" }.Any((item) => formFileOne.FileName.ToLower().EndsWith(item)))
                                        {
                                            throw new AbpValidationException("您上传的文件格式必须为png、jpg、bmp中的一种");
                                        }
                                        Guid guid = Guid.NewGuid();
                                        var fileFullPath = Path.Combine(filePath, guid.ToString() + Path.GetExtension(formFileOne.FileName));
                                        using (var stream = System.IO.File.Create(fileFullPath))
                                        {
                                            await formFileOne.CopyToAsync(stream);
                                            stream.Flush();
                                        }
                                        workContentStr = workContentStr + "," + "<img width=\"505\" height=\"379\" src=\"../DownLoadFileRootPath/" + TechniqueNumber + "/" + guid.ToString() + Path.GetExtension(formFileOne.FileName) + "\" border=\"0\"><p>" + photos[i].FileName.Substring(0) + "</p>";
                                    }
                                    else
                                    {
                                        var tempImage = images[photos[i].Id - 1];
                                        string url = ConfigHelper.GetAppSetting("App", "GetAppUrl");
                                        var src = tempImage.Src.Replace(url + @"/", "../");
                                        workContentStr = workContentStr + "," + "<img width=" + tempImage.Width + " height=" + tempImage.Height + " src=" + src + " border=" + tempImage.Border + "><p>" + tempImage.Name + "</p>";
                                    }
                                }
                                else
                                {
                                    var formFileOne = formFiles.Where(d => d.FileName.StartsWith(photos[i].FileName.ToString())).FirstOrDefault();
                                    if (formFileOne != null)
                                    {
                                        if (!new[] { ".png", ".jpg", ".bmp" }.Any((item) => formFileOne.FileName.ToLower().EndsWith(item)))
                                        {
                                            throw new AbpValidationException("您上传的文件格式必须为png、jpg、bmp中的一种");
                                        }
                                        Guid guid = Guid.NewGuid();
                                        var fileFullPath = Path.Combine(filePath, guid.ToString() + Path.GetExtension(formFileOne.FileName));
                                        using (var stream = System.IO.File.Create(fileFullPath))
                                        {
                                            await formFileOne.CopyToAsync(stream);
                                            stream.Flush();
                                        }
                                        workContentStr = workContentStr + "," + "<img width=\"505\" height=\"379\" src=\"../DownLoadFileRootPath/" + TechniqueNumber + "/" + guid.ToString() + Path.GetExtension(formFileOne.FileName) + "\" border=\"0\"><p>" + photos[i].FileName.Substring(0) + "</p>";
                                    }
                                }

                            }

                            if (workContentStr != "")
                            {
                                nodeWork.WorkStepContent = workContentStr.Replace(",", "");
                                await _workStepEntityRepository.UpdateAsync(nodeWork);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < photos.Count; i++)
                            {
                                var formFileOne = formFiles.Where(d => d.FileName.StartsWith(photos[i].FileName.ToString())).FirstOrDefault();
                                if (formFileOne != null)
                                {
                                    if (!new[] { ".png", ".jpg", ".bmp" }.Any((item) => formFileOne.FileName.ToLower().EndsWith(item)))
                                    {
                                        throw new AbpValidationException("您上传的文件格式必须为png、jpg、bmp中的一种");
                                    }
                                    Guid guid = Guid.NewGuid();
                                    var fileFullPath = Path.Combine(filePath, guid.ToString() + Path.GetExtension(formFileOne.FileName));
                                    using (var stream = System.IO.File.Create(fileFullPath))
                                    {
                                        await formFileOne.CopyToAsync(stream);
                                        stream.Flush();
                                    }
                                    workContentStr = workContentStr + "," + "<img width=\"505\" height=\"379\" src=\"../DownLoadFileRootPath/" + TechniqueNumber + "/" + guid.ToString() + Path.GetExtension(formFileOne.FileName) + "\" border=\"0\"><p>" + photos[i].FileName.Substring(1) + "</p>";
                                }
                            }

                            if (workContentStr != "")
                            {
                                nodeWork.WorkStepContent = workContentStr.Replace(",", "");
                                await _workStepEntityRepository.UpdateAsync(nodeWork);
                            }


                        }
                    }
                }
                resultMessage.code = 0;
                return resultMessage;

            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = "文件上传失败，原因" + ex.Message;
                return resultMessage;
            }
        }

        public List<ImageParm> GetImageParms(Guid guid)
        {
            //根据图片数据格式 拆分数据 主要 就是 width height src border 这四种属性 然后进行组装
            var tempWork = _workStepEntityRepository.Get(guid);
            string str = tempWork.WorkStepContent;
            List<ImageParm> parms = new List<ImageParm>();
            if (!string.IsNullOrEmpty(str))
            {
                var contentArray = str.Split("</p>");
                foreach (var item in contentArray)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        var widthIndex = item.IndexOf("width");
                        var height = item.IndexOf("height");
                        var src = item.IndexOf("src");
                        var border = item.IndexOf("border");
                        var P = item.IndexOf("><p>");
                        ImageParm iamgeParm = new ImageParm();
                        if (widthIndex != -1)
                        {
                            var widthS = Regex.Replace(item.Substring(widthIndex, height - widthIndex), @"[^0-9]+", "");
                            iamgeParm.Width = widthS;
                        }
                        if (height != -1)
                        {
                            var heightS = Regex.Replace(item.Substring(height, src - height), @"[^0-9]+", "");
                            iamgeParm.Height = heightS;
                        }
                        if (src != -1)
                        {
                            string url = ConfigHelper.GetAppSetting("App", "GetAppUrl");
                            var srcS = item.Substring(src, border - src).Replace("\"", "").Replace("=", "").Replace("src", "").Replace(" ", "").Replace("../", url + @"/");
                            iamgeParm.Src = srcS;
                        }
                        if (border != -1)
                        {
                            var borderS = Regex.Replace(item.Substring(border, P - border), @"[^0-9]+", "");
                            iamgeParm.Border = borderS;
                        }
                        if (P != -1)
                        {
                            var name = item.Substring(P).Replace("><p>", "");
                            iamgeParm.Name = name;
                        }
                        if (iamgeParm != null)
                        {
                            parms.Add(iamgeParm);
                        }
                    }
                }
            }
            return parms;
        }
        /// <summary>
        /// 导出本系统用户权限Json
        /// </summary>
        /// <returns></returns>
        public ResultMessage GetUserPers()
        {
            ResultMessage resultMessage = GetUserPermissionsJson();

            return resultMessage;

        }
        /// <summary>
        /// 获取权限Json 导出
        /// </summary>
        /// <returns></returns>
        private ResultMessage GetUserPermissionsJson()
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                var userPermissions = GetUserPermissions();
                List<PadJurisdictionDto> dtolst = new List<PadJurisdictionDto>();
                dtolst = userPermissions.Result;
                var permissions = userPermissions.Result;

                String DateStr = System.DateTime.Now.ToString("yyyyMMddHHmm");


                string treePath = "../../Bop/User/" + DateStr + "/";
                if (!Directory.Exists(treePath))
                {
                    Directory.CreateDirectory(treePath);
                }
                string treefp = treePath + "user.json"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
                if (File.Exists(treefp))  // 判断是否已有相同文件 
                {
                    File.Delete(treefp);
                }
                var listjson = Newtonsoft.Json.JsonConvert.SerializeObject(permissions);
                File.WriteAllText(treefp, listjson);



                string fileSavePath = Environment.CurrentDirectory + "/wwwroot/Zip/User/" + DateStr + "/";
                if (!Directory.Exists(fileSavePath))
                {
                    Directory.CreateDirectory(fileSavePath);
                }
                string zipTreeName = fileSavePath + "user.zip";
                if (File.Exists(zipTreeName))
                {
                    File.Delete(zipTreeName);
                }
                CompressMulti(new List<string> { treePath }, zipTreeName, true);
                // ZipFile.CreateFromDirectory(treePath, zipTreeName);

                resultMessage.code = 0;
                resultMessage.Message = ConfigHelper.GetAppSetting("App", "GetAppUrl") + "/Zip/User/" + DateStr + "/user.zip";
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }

        }

        private class ExportShootingRangeBop
        {
            public List<BopDesc> bopDescs { get; set; } = new List<BopDesc>();
            public List<BopNode> bopNodes { get; set; } = new List<BopNode>();

            public List<TechniqueEntity> techniqueEntities { get; set; } = new List<TechniqueEntity>();

            public List<TableBase> tableBases { get; set; } = new List<TableBase>();

            public List<LoadPieceEntity> loadPieceEntities { get; set; } = new List<LoadPieceEntity>();

            public List<MakeResourcesEntity> makeResourcesEntities { get; set; } = new List<MakeResourcesEntity>();

            public List<VideoEntity> videoEntities { get; set; } = new List<VideoEntity>();
            /// <summary>
            /// 工艺路线
            /// </summary>
            public List<ProcessLine> processLines { get; set; } = new List<ProcessLine>();
        }

        private class InportShootingRangeBop
        {
            public List<BopDesc> bopDescs { get; set; }

            public List<TechniqueEntity> techniqueEntities { get; set; } = new List<TechniqueEntity>();

            public List<TableBaseShootDto> tableBases { get; set; } = new List<TableBaseShootDto>();

            public List<LoadPieceEntity> loadPieceEntities { get; set; } = new List<LoadPieceEntity>();

            public List<MakeResourcesEntity> makeResourcesEntities { get; set; } = new List<MakeResourcesEntity>();

            public List<VideoEntity> videoEntities { get; set; } = new List<VideoEntity>();
            /// <summary>
            /// 工艺路线
            /// </summary>
            public List<ProcessLine> processLines { get; set; } = new List<ProcessLine>();
        }
        #region 靶场
        /// <summary>
        /// Bop靶场导出
        /// </summary>
        /// <param name="bopDescId"></param>
        /// <returns></returns>
        public ResultMessage GetShootingRangeOld(Guid bopDescId)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                List<Guid> LineIds = new List<Guid>();
                ExportShootingRangeBop shootingRangeBop = new ExportShootingRangeBop();
                var bopDesc = _bopDescRepository.GetAll().Include(d => d.BopNodes).Where(d => d.Id == bopDescId).First();
                shootingRangeBop.bopDescs.Add(bopDesc);
                LineIds.Add(bopDesc.Id);
                var bopNodeList = _bopNodeRepository.GetAll().Where(d => d.BopDescId == bopDescId);
                List<string> techniqueNumbers = new List<string>();
                if (bopNodeList.Count() > 0)
                {
                    //获取 工艺 工序 工步 关联表 工艺路线 信息
                    LineIds.AddRange(bopNodeList.Select(d => d.Id));
                    var tech = (from cc in _techniqueEntityRepository.GetAll().Include(d => d.ProcessesEntities).ThenInclude(d => d.WorkStepEntities)
                                join mm in bopNodeList on cc.Id equals mm.TechniqueEntityId
                                select cc);
                    if (tech.Count() > 0)
                    {
                        techniqueNumbers.AddRange(tech.Select(d => d.TechniqueNumber));
                        shootingRangeBop.techniqueEntities.AddRange(tech);

                        var pro = (from cc in _processesEntityRepository.GetAll()
                                   join mm in tech on cc.TechniqueEntityId equals mm.Id
                                   select cc);
                        if (pro.Count() > 0)
                        {
                            LineIds.AddRange(pro.Select(d => d.Id));
                        }

                        var work = (from cc in _workStepEntityRepository.GetAll()
                                    join mm in tech on cc.TechniqueEntityId equals mm.Id
                                    select cc);

                        var table = (from cc in _tableBaseEntity.GetAllIncluding(a => a.RecordRequirements, b => b.InspectionSignature, c => c.MeasuredResult, d => d.Environment, e => e.MultiMedia)
                                     join mm in work on cc.WorkStepEntityId equals mm.Id
                                     select cc);
                        if (table.Count() > 0)
                        {
                            shootingRangeBop.tableBases.AddRange(table);
                        }

                        var load = (from cc in _loadPieceRepository.GetAll()
                                    join mm in work on cc.WorkStepEntityId equals mm.Id
                                    select cc);
                        if (load.Count() > 0)
                        {
                            shootingRangeBop.loadPieceEntities.AddRange(load);
                        }
                        var make = (from cc in _makeResourcesEntityRepository.GetAll()
                                    join mm in work on cc.WorkStepEntityId equals mm.Id
                                    select cc);
                        if (make.Count() > 0)
                        {
                            shootingRangeBop.makeResourcesEntities.AddRange(make);
                        }

                        var video = (from cc in _videoEntityRepository.GetAll()
                                     join mm in work on cc.WorkStepEntityId equals mm.Id
                                     select cc);
                        if (video.Count() > 0)
                        {
                            shootingRangeBop.videoEntities.AddRange(video);
                        }
                        var proLine = (from cc in _processLineRepository.GetAll()
                                       join mm in LineIds on cc.PPtr equals mm
                                       select cc);
                        if (proLine.Count() > 0)
                        {
                            shootingRangeBop.processLines.AddRange(proLine);
                        }
                    }


                }
                String DateStr = System.DateTime.Now.ToString("yyyyMMddHHmm");

                string treePath = "../../Bop/BopShootingRange/" + DateStr + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "/";
                if (!Directory.Exists(treePath))
                {
                    Directory.CreateDirectory(treePath);
                }
                string treefp = treePath + bopDesc.Model + "_" + bopDesc.LotNo + "_shootBop.json"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
                if (File.Exists(treefp))  // 判断是否已有相同文件 
                {
                    File.Delete(treefp);
                }
                //改为通过流写入，解决json太大写入不成功问题
                //var treeJson = Newtonsoft.Json.JsonConvert.SerializeObject(shootingRangeBop);
                JsonSerializer serializer = new JsonSerializer();
                StreamWriter sw = new StreamWriter(treefp, true);
                serializer.Serialize(new JsonTextWriter(sw), shootingRangeBop);
                sw.Flush();
                sw.Close();
                //File.WriteAllText(treefp, treeJson);
                foreach (var item in techniqueNumbers)
                {
                    string path = "../../Bop/BopShootingRange/" + DateStr + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "/" + item + "/";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    string fp = path + item + ".json"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
                    if (File.Exists(fp))  // 判断是否已有相同文件 
                    {
                        File.Delete(fp);
                    }
                    string srcPatch = Environment.CurrentDirectory + "/wwwroot/DownLoadFileRootPath/" + item + "/";
                    if (!Directory.Exists(srcPatch))
                    {
                        Directory.CreateDirectory(srcPatch);
                    }
                    if (!CopyDir(srcPatch, path))
                    {
                        resultMessage.code = 1;
                        resultMessage.Message = "复制文件文件失败!";
                        return resultMessage;
                        //throw new UserFriendlyException("复制文件文件失败!");
                    }
                }
                string fileSavePath = Environment.CurrentDirectory + "/wwwroot/Zip/BopShootingRange/" + DateStr + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "/";
                if (!Directory.Exists(fileSavePath))
                {
                    Directory.CreateDirectory(fileSavePath);
                }
                string zipTreeName = fileSavePath + bopDesc.Model + "_" + bopDesc.LotNo + "_shootBop.zip";
                if (File.Exists(zipTreeName))
                {
                    File.Delete(zipTreeName);
                }
                CompressMulti(new List<string> { treePath }, zipTreeName, true);
                //ZipFile.CreateFromDirectory(treePath, zipTreeName);
                resultMessage.code = 0;
                resultMessage.Message = ConfigHelper.GetAppSetting("App", "GetAppUrl") + "/Zip/BopShootingRange/" + DateStr + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "_shootBop.zip";
                return resultMessage;
            }
            catch (Exception ex)
            {
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }
        public ResultMessage GetShootingRange(Guid bopDescId)
        {
            ResultMessage resultMessage = new ResultMessage();
            try
            {
                List<Guid> LineIds = new List<Guid>();
                ExportShootingRangeBop shootingRangeBop = new ExportShootingRangeBop();
                var bopDesc = _bopDescRepository.GetAll().Include(d => d.BopNodes).Where(d => d.Id == bopDescId).First();
                shootingRangeBop.bopDescs.Add(bopDesc);
                LineIds.Add(bopDesc.Id);
                var bopNodeList = _bopNodeRepository.GetAll().Where(d => d.BopDescId == bopDescId);
                List<string> techniqueNumbers = new List<string>();
                String DateStr = System.DateTime.Now.ToString("yyyyMMddHHmm");
                string bopePath = "../../Bop/BopShootingRange/" + DateStr + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "/";
                if (bopNodeList.Count() > 0)
                {
                    shootingRangeBop.bopNodes.AddRange(bopNodeList);
                    if (!Directory.Exists(bopePath))
                    {
                        Directory.CreateDirectory(bopePath);
                    }
                    string bopfp = bopePath + bopDesc.Model + "_" + bopDesc.LotNo + "_shootBop.json";
                    if (File.Exists(bopfp))  // 判断是否已有相同文件 
                    {
                        File.Delete(bopfp);
                    }
                    JsonSerializer serializer = new JsonSerializer();
                    StreamWriter sw = new StreamWriter(bopfp, false);
                    serializer.Serialize(new JsonTextWriter(sw), shootingRangeBop);
                    sw.Flush();
                    sw.Close();

                    JsonSerializer serializerData = default;
                    StreamWriter swData = default;
                    ExportShootingRangeBop shootingRangeBopExport = null;
                    //规程导出
                    var techEntity = (from cc in _techniqueEntityRepository.GetAll().Include(d => d.ProcessesEntities).ThenInclude(d => d.WorkStepEntities)
                                      join mm in bopNodeList on cc.Id equals mm.TechniqueEntityId
                                      select cc);

                    var processesEntity = (from cc in _processesEntityRepository.GetAll()
                                           join mm in techEntity on cc.TechniqueEntityId equals mm.Id
                                           select cc).ToList();
                    if (processesEntity.Count() > 0)
                    {
                        LineIds.AddRange(processesEntity.Select(d => d.Id));
                    }

                    var workStepEntity = (from cc in _workStepEntityRepository.GetAll()
                                          join mm in techEntity on cc.TechniqueEntityId equals mm.Id
                                          select cc).ToList();

                    var tablebaseErtity = (from cc in _tableBaseEntity.GetAllIncluding(a => a.RecordRequirements, b => b.InspectionSignature, c => c.MeasuredResult, d => d.Environment, e => e.MultiMedia)
                                           join mm in workStepEntity on cc.WorkStepEntityId equals mm.Id
                                           select cc).AsNoTracking().ToList();

                    var loadPiece = (from cc in _loadPieceRepository.GetAll()
                                     join mm in workStepEntity on cc.WorkStepEntityId equals mm.Id
                                     select cc).ToList();

                    var makeResourcesEntity = (from cc in _makeResourcesEntityRepository.GetAll()
                                               join mm in workStepEntity on cc.WorkStepEntityId equals mm.Id
                                               select cc).ToList();

                    var videoEntity = (from cc in _videoEntityRepository.GetAll()
                                       join mm in workStepEntity on cc.WorkStepEntityId equals mm.Id
                                       select cc).ToList();

                    //var processLine = (from cc in _processLineRepository.GetAll()
                    //               join mm in LineIds on cc.PPtr equals mm
                    //               select cc).ToList();
                    foreach (var item in bopNodeList)
                    {
                         shootingRangeBopExport = new ExportShootingRangeBop();
                        //获取 工艺 工序 工步 关联表 工艺路线 信息
                        LineIds = bopNodeList.Where(t => t.Id == item.Id).Select(s => s.Id).ToList();
                        var tech = (from cc in techEntity
                                    .Where(s => s.Id == item.TechniqueEntityId)
                                    select cc).ToList();
                        if (tech.Count() > 0)
                        {
                            var techNumber = tech.FirstOrDefault().TechniqueNumber;
                            techniqueNumbers.AddRange(tech.Select(d => d.TechniqueNumber));
                            shootingRangeBopExport.techniqueEntities.AddRange(tech);

                            var pro = (from cc in processesEntity
                                       join mm in tech on cc.TechniqueEntityId equals mm.Id
                                       select cc).ToList();
                            if (pro.Count() > 0)
                            {
                                LineIds.AddRange(pro.Select(d => d.Id));
                            }

                            var work = (from cc in workStepEntity
                                        join mm in tech on cc.TechniqueEntityId equals mm.Id
                                        select cc).ToList();

                            var table = (from cc in tablebaseErtity
                                         join mm in work on cc.WorkStepEntityId equals mm.Id
                                         select cc).ToList();
                            if (table.Count() > 0)
                            {
                                shootingRangeBopExport.tableBases.AddRange(table);
                            }

                            var load = (from cc in loadPiece
                                        join mm in work on cc.WorkStepEntityId equals mm.Id
                                        select cc).ToList();
                            if (load.Count() > 0)
                            {
                                shootingRangeBopExport.loadPieceEntities.AddRange(load);
                            }
                            var make = (from cc in makeResourcesEntity
                                        join mm in work on cc.WorkStepEntityId equals mm.Id
                                        select cc).ToList();
                            if (make.Count() > 0)
                            {
                                shootingRangeBopExport.makeResourcesEntities.AddRange(make);
                            }

                            var video = (from cc in videoEntity
                                         join mm in work on cc.WorkStepEntityId equals mm.Id
                                         select cc).ToList();
                            if (video.Count() > 0)
                            {
                                shootingRangeBopExport.videoEntities.AddRange(video);
                            }
                            //var proLine = (from cc in processLine
                            //               join mm in LineIds on cc.PPtr equals mm
                            //               select cc).ToList();
                            //if (proLine.Count() > 0)
                            //{
                            //    shootingRangeBopExport.processLines.AddRange(proLine);
                            //}
                            string path = "../../Bop/BopShootingRange/" + DateStr + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "/" + techNumber + "/";
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }
                            string fp = path + techNumber + ".json"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
                            if (File.Exists(fp))  // 判断是否已有相同文件 
                            {
                                File.Delete(fp);
                            }
                            serializerData = new JsonSerializer();
                            swData = new StreamWriter(fp, false);
                            serializerData.Serialize(new JsonTextWriter(swData), shootingRangeBopExport);
                            swData.Flush();
                            swData.Close();
                            string pathPhoto = "../../Bop/BopShootingRange/" + DateStr + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "/" + techNumber + "/";
                            if (!Directory.Exists(pathPhoto))
                            {
                                Directory.CreateDirectory(pathPhoto);
                            }
                            string srcPatch = Environment.CurrentDirectory + "/wwwroot/DownLoadFileRootPath/" + techNumber + "/";
                            if (!Directory.Exists(srcPatch))
                            {
                                Directory.CreateDirectory(srcPatch);
                            }
                            if (!CopyDir(srcPatch, pathPhoto))
                            {
                                resultMessage.code = 1;
                                resultMessage.Message = "复制文件文件失败!";
                                return resultMessage;
                            }
                        }
                    }
                    //swData.Close();
                    //swData.Dispose();
                    //GC.Collect();
                }
                string fileSavePath = Environment.CurrentDirectory + "/wwwroot/Zip/BopShootingRange/" + DateStr + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "/";
                if (!Directory.Exists(fileSavePath))
                {
                    Directory.CreateDirectory(fileSavePath);
                }
                string zipTreeName = fileSavePath + bopDesc.Model + "_" + bopDesc.LotNo + "_shootBop.zip"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
                if (File.Exists(fileSavePath))  // 判断是否已有相同文件 
                {
                    File.Delete(fileSavePath);
                }

                CompressMulti(new List<string> { bopePath }, zipTreeName, true);

                //ZipFile.CreateFromDirectory(treePath, zipTreeName);
                resultMessage.code = 0;
                resultMessage.Message = ConfigHelper.GetAppSetting("App", "GetAppUrl") + "/Zip/BopShootingRange/" + DateStr + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "/" + bopDesc.Model + "_" + bopDesc.LotNo + "_shootBop.zip";
                return resultMessage;
            }
            catch (Exception ex)
            {
                System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
                ConfigHelper.CreateLogText("Line: " + trace.GetFrame(0).GetFileLineNumber());
                resultMessage.code = 1;
                resultMessage.Message = ex.Message;
                return resultMessage;
            }
        }


        //public ResultMessage GetShootingRange(Guid bopDescId)
        //{
        //    // 任务-节点-工序-工步
        //    ResultMessage resultMessage = new ResultMessage();
        //    try
        //    {
        //        var tempDesc = _bopDescRepository.FirstOrDefault(s => s.Id == bopDescId);
        //        if (tempDesc == null)
        //        {
        //            resultMessage.code = 1;
        //            resultMessage.Message = "没有找到该任务";
        //            return resultMessage;
        //        }
        //        List<Guid?> techIdList = _bopNodeRepository.GetAll().Where(d => d.BopDescId == bopDescId).Where(d => d.TechniqueEntityId != null).Select(d => d.TechniqueEntityId).ToList();
        //        BopExportput bopExportput = new BopExportput();
        //        BopTreeJson bopTree = new BopTreeJson();
        //        long edtion = 0;
        //        bopTree = GetShootBopTreeJson(tempDesc.ModelId.Value, tempDesc.LotNoId.Value, ref edtion);
        //        //var bopDesc1= _bopDescRepository.GetAll().Where(d => d.ModelId == input.ModelId && d.LotNoId == input.LotNoId).FirstOrDefault();
        //        //input.TechIdList = _bopNodeRepository.GetAll().Where(d => d.BopDescId == bopDesc1.Id).Where(d => d.TechniqueEntityId != null).Select(d=>d.TechniqueEntityId).ToList();

        //        if (techIdList == null)
        //        {
        //            resultMessage.code = 1;
        //            resultMessage.Message = "该任务下没有规程!";
        //            return resultMessage;
        //            //throw new UserFriendlyException("请先选择要导出的规程!");
        //        }
        //        if (bopTree != null)
        //        {
        //            String DateStr = System.DateTime.Now.ToString("yyyyMMddHHmm");
        //            //var tempDesc = _bopDescRepository.FirstOrDefault(d => d.ModelId == bopDesc.ModelId && d.LotNoId == bopDesc.LotNoId);
        //            string treePath = "../../Bop/BopShootingRange/" + DateStr + "/" + tempDesc.Model + "_" + tempDesc.LotNo + "/";
        //            if (!Directory.Exists(treePath))
        //            {
        //                Directory.CreateDirectory(treePath);
        //            }
        //            string treefp = treePath + tempDesc.Model + "_" + tempDesc.LotNo + "_shootBop.json"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
        //            if (File.Exists(treefp))  // 判断是否已有相同文件 
        //            {
        //                File.Delete(treefp);
        //            }
        //            var treeJson = Newtonsoft.Json.JsonConvert.SerializeObject(bopTree);
        //            File.WriteAllText(treefp, treeJson);

        //            //if (!Directory.Exists("../../ZIP/BopTree/" + tempDesc.Model + tempDesc.LotNo + "/"))
        //            //{
        //            //    Directory.CreateDirectory("../../ZIP/BopTree/" + tempDesc.Model + tempDesc.LotNo + "/");
        //            //}
        //            //string zipTreeName = "../../ZIP/BopTree/" + tempDesc.Model + tempDesc.LotNo + "/" + tempDesc.Model + tempDesc.LotNo + ".zip";
        //            //if (File.Exists(zipTreeName))
        //            //{
        //            //    File.Delete(zipTreeName);
        //            //}
        //            //ZipFile.CreateFromDirectory(treePath, zipTreeName);
        //            //规程数据
        //            var tempData = (from tempTech in _techniqueEntityRepository.GetAll()
        //                            join tempNode in _bopNodeRepository.GetAll() on tempTech.Id equals tempNode.TechniqueEntityId
        //                            join tempBopdesc in _bopDescRepository.GetAll() on tempNode.BopDescId equals tempBopdesc.Id
        //                            join ttempTech in techIdList on tempTech.Id equals ttempTech
        //                            where tempBopdesc.ModelId == tempDesc.ModelId && tempBopdesc.LotNoId == tempDesc.LotNoId
        //                            select new
        //                            {
        //                                Id = tempTech.Id,
        //                                Model = tempBopdesc.Model,
        //                                ModelName = tempBopdesc.ModelName,
        //                                LotNo = tempBopdesc.LotNo,
        //                                DrawingNo = tempBopdesc.DrawingNo,
        //                                StageSign = tempBopdesc.StageSign,
        //                                BopDescId = tempBopdesc.Id,
        //                                BopNodeId = tempNode.Id,
        //                                Technique = tempTech,
        //                            }).ToList();
        //            if (tempData.Count > 0)
        //            {
        //                //List<BopTaskOutDto> bopTasks = new List<BopTaskOutDto>();
        //                for (int i = 0; i < tempData.Count; i++)
        //                {
        //                    BopTaskOutDto bopTask = new BopTaskOutDto();
        //                    bopTask.Id = tempData[i].Id;
        //                    bopTask.Model = tempData[i].Model;
        //                    bopTask.ModelName = tempData[i].ModelName;
        //                    bopTask.LotNo = tempData[i].LotNo;
        //                    bopTask.DrawingNo = tempData[i].DrawingNo;
        //                    bopTask.StageSign = tempData[i].StageSign;
        //                    TechniqueOutDto technique = new TechniqueOutDto();
        //                    technique = ObjectMapper.Map<TechniqueOutDto>(tempData[i].Technique);
        //                    var processess = _processesEntityRepository.GetAll().Where(p => p.TechniqueEntityId == tempData[i].Technique.Id).OrderBy(p => p.ProcessesSequence).ToList();
        //                    technique.ProcessesListDto = ObjectMapper.Map<List<ProcessesOutDto>>(processess);
        //                    List<TableNameDictionary> tableNameDictionary = new List<TableNameDictionary>();
        //                    //封装工序数据
        //                    foreach (var item in technique.ProcessesListDto)
        //                    {
        //                        if (!string.IsNullOrEmpty(item.ProcessesExplain))
        //                        {
        //                            item.ProcessesExplain = item.ProcessesExplain.Replace("../DownLoadFileRootPath/" + technique.TechniqueNumber + "/", "");
        //                        }
        //                        //封装工步数据
        //                        var workSteps = _workStepEntityRepository.GetAll().Where(p => p.ProcessesEntityId == item.Id).OrderBy(p => p.WorkStepNumber).ToList();
        //                        item.WorkStepListDto = ObjectMapper.Map<List<WorkStepOutDto>>(workSteps);
        //                        foreach (var workStep in item.WorkStepListDto)
        //                        {
        //                            if (workStep.WorkStepContent != null)
        //                            {
        //                                workStep.WorkStepContent = workStep.WorkStepContent.Replace("../DownLoadFileRootPath/" + technique.TechniqueNumber + "/", "");// GetImageStr(workStep.WorkStepContent);
        //                            }

        //                            tableNameDictionary.Clear();
        //                            WorkStepJsonAnalysis(workStep, tableNameDictionary);
        //                        }
        //                    }
        //                    technique.BopDescId = tempData[i].BopDescId;
        //                    technique.BopNodeId = tempData[i].BopNodeId;
        //                    //var tempBopNode = _bopNodeRepository.Get(tempData[i].BopNodeId);
        //                    bopTask.TechniqueTask = technique;

        //                    string path = "../../Bop/BopShootingRange/" + DateStr + "/" + tempData[i].Model + "_" + tempData[i].LotNo + "/" + tempData[i].Technique.TechniqueNumber + "/";
        //                    if (!Directory.Exists(path))
        //                    {
        //                        Directory.CreateDirectory(path);
        //                    }
        //                    string fp = path + tempData[i].Technique.TechniqueNumber + ".json"; //"_" +System.DateTime.Now.ToString("yyyyMMddHHmm")
        //                    if (File.Exists(fp))  // 判断是否已有相同文件 
        //                    {
        //                        File.Delete(fp);
        //                    }
        //                    var listjson = Newtonsoft.Json.JsonConvert.SerializeObject(bopTask);
        //                    File.WriteAllText(fp, listjson);
        //                    //string srcPatch = Environment.CurrentDirectory + "/wwwroot/DownLoadFileRootPath/" + tempData[i].Technique.TechniqueNumber + "/";
        //                    //if (!Directory.Exists(srcPatch))
        //                    //{
        //                    //    Directory.CreateDirectory(srcPatch);
        //                    //}
        //                    //if (CopyDir(srcPatch, path))
        //                    //{
        //                    //    //string zipdir = "../../ZIP/BopTree/" + tempData[i].Model + tempData[i].LotNo+"/"+ tempData[i].Technique.TechniqueNumber + "/";
        //                    //    //if (!Directory.Exists(zipdir))
        //                    //    //{
        //                    //    //    Directory.CreateDirectory(zipdir);
        //                    //    //}
        //                    //    //string  zipPathName = zipdir + tempData[i].Technique.TechniqueNumber + ".zip";
        //                    //    //if (File.Exists(zipPathName))
        //                    //    //{
        //                    //    //    File.Delete(zipPathName);
        //                    //    //}
        //                    //    //ZipFile.CreateFromDirectory(path, zipPathName);
        //                    //}
        //                    //else
        //                    //{
        //                    //    resultMessage.code = 1;
        //                    //    resultMessage.Message = "复制文件文件失败!";
        //                    //    return resultMessage;
        //                    //    //throw new UserFriendlyException("复制文件文件失败!");
        //                    //}
        //                }

        //                string fileSavePath = Environment.CurrentDirectory + "/wwwroot/Zip/BopShootingRange/" + DateStr + "/" + tempDesc.Model + "_" + tempDesc.LotNo + "/";
        //                if (!Directory.Exists(fileSavePath))
        //                {
        //                    Directory.CreateDirectory(fileSavePath);
        //                }
        //                string zipTreeName = fileSavePath + tempDesc.Model + "_" + tempDesc.LotNo + "_shootBop.zip";
        //                if (File.Exists(zipTreeName))
        //                {
        //                    File.Delete(zipTreeName);
        //                }
        //                //组装打包然后压缩
        //                CompressMulti(new List<string> { treePath }, zipTreeName, true);
        //                //ZipFile.CreateFromDirectory(treePath, zipTreeName);
        //                resultMessage.code = 0;
        //                resultMessage.Message = ConfigHelper.GetAppSetting("App", "GetAppUrl") + "/Zip/BopShootingRange/" + DateStr + "/" + tempDesc.Model + "_" + tempDesc.LotNo + "/" + tempDesc.Model + "_" + tempDesc.LotNo + "_shootBop.zip";
        //                //_iOperationHistoryAppService.InsertOperationLogNew(tempDesc.Id, OperationHistory.BusinessTypes.导出数据包, OperationHistory.OperationTypes.批量导出规程, "【v" + edtion.ToString() + "】" + resultMessage.Message);
        //                return resultMessage;
        //                //return ConfigHelper.GetAppSetting("App", "GetAppUrl") + "/Zip/BopTree/" + DateStr + "/" + tempDesc.Model + tempDesc.LotNo + "/" + tempDesc.Model + tempDesc.LotNo + ".zip";
        //            }
        //            else
        //            {
        //                resultMessage.code = 1;
        //                resultMessage.Message = "未查找到匹配的Bop数据!";
        //                return resultMessage;
        //                //throw new UserFriendlyException("未查找到匹配的Bop数据!");

        //            }
        //        }
        //        else
        //        {
        //            resultMessage.code = 1;
        //            resultMessage.Message = "未查找到匹配的Bop数据!";
        //            return resultMessage;
        //            //throw new UserFriendlyException("未查找到匹配的Bop数据!");
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        resultMessage.code = 1;
        //        resultMessage.Message = ex.Message;
        //        return resultMessage;
        //    }
        //}
        //[Microsoft.AspNetCore.Mvc.DisableRequestSizeLimit]
        public async Task<ResultMessage> ShootingBigRangeBop(string file)
        {

            ResultMessage resultMessage = new ResultMessage();
            try
            {

                string uniqueFileName = null;

                if (file != null)
                {
                    string rootPath = Environment.CurrentDirectory + "/wwwroot/";
                    string[] formatArray = { ".zip", ".7z" };
                    //文件格式
                    var fileExtension = Path.GetExtension(file);
                    if (!formatArray.Contains(fileExtension))
                    {

                        resultMessage.code = 1;
                        resultMessage.Message = "上传文件格式错误!";
                        return resultMessage;

                    }

                    //文件名称
                    var jsonName = file.Split('.')[0];
                    if (!jsonName.Contains("_shootBop"))
                    {
                        resultMessage.code = 1;
                        resultMessage.Message = "上传文件不合法！";
                        return resultMessage;
                    }

                    string fileSaveBigRootDir = ConfigHelper.GetAppSetting("App", "BigFileRootPath");
                    //读取文件保存的根目录
                    string fileSaveRootDir = ConfigHelper.GetAppSetting("App", "ShootingRangePath");
                    string fileSavePath = rootPath + fileSaveBigRootDir;
                    //文件名称
                    var jsonFileName = file.Split('.')[0];
                    //文件路径
                    string ZipPath = fileSavePath + "/" + file;
                    //目标路径
                    String DateStr = System.DateTime.Now.ToString("yyyyMMddHHmm");
                    string FilePath = Environment.CurrentDirectory + "/wwwroot/" + fileSaveRootDir + "/" + jsonFileName + "/" + DateStr;
                    //如果不需要嵌入到接口 去掉用exe解压
                    if (ZipOpen(ZipPath, FilePath, true))
                    {

                    }
                    else
                    {
                        //return;
                    }

                    //文件保存的路径(应用的工作目录+文件夹相对路径);
                    //string fileSavePath = Environment.CurrentDirectory + "/wwwroot/" + fileSaveRootDir;
                    //if (!Directory.Exists(fileSavePath))
                    //{
                    //    Directory.CreateDirectory(fileSavePath);
                    //}
                    //uniqueFileName = jsonName + fileExtension;
                    //string filePath = Path.Combine(fileSavePath, uniqueFileName);
                    //using (var fileStream = new FileStream(filePath, FileMode.Create))
                    //{
                    //    file.CopyTo(fileStream);
                    //    fileStream.Flush();
                    //}

                    //var fileSave = uniqueFileName.Split('.')[0];



                    //ZipFile.ExtractToDirectory(@filePath, destinationDirectoryName);
                    string jsonStr = "";
                    List<InportShootingRangeBop> inportQShootingRangeBops = new List<InportShootingRangeBop>();
                    var directory = new DirectoryInfo(FilePath + "/");
                    var logFiles = directory.GetFiles("*.json", SearchOption.AllDirectories).ToList();
                    // List<Dto.TableReturnDto.Technique.BackTaskFormat> Tasks = new List<Dto.TableReturnDto.Technique.BackTaskFormat>();
                    for (int i = 0; i < logFiles.Count; i++)
                    {
                        InportShootingRangeBop inportShootingRangeBop = new InportShootingRangeBop();
                        var techName = logFiles[i].Name.Split('.')[0];
                        if (techName.Replace("_", "") != jsonName.Replace("_", ""))
                        {
                            BackTaskFormat backTask = new BackTaskFormat();
                            backTask.TechniqueNum = techName;

                            jsonStr = ReadJson.GetFileJson(FilePath + "/" + techName + "/" + techName + ".json");
                            inportShootingRangeBop = JsonConvert.DeserializeObject<InportShootingRangeBop>(jsonStr);
                            inportQShootingRangeBops.Add(inportShootingRangeBop);
                            ////曲冰修改
                            //backTask.FilePath =;
                            // Tasks.Add(backTask);
                        }
                        else
                        {
                            jsonStr = ReadJson.GetFileJson(logFiles[0].ToString());
                            inportShootingRangeBop = JsonConvert.DeserializeObject<InportShootingRangeBop>(jsonStr);
                            inportQShootingRangeBops.Add(inportShootingRangeBop);
                        }

                    }




                    //var jsonStr = ReadJson.GetFileJson(FilePath + "/" + jsonFileName + ".json");
                    // var ReturnBopTaskOutDto = JsonConvert.DeserializeObject<InportShootingRangeBop>(jsonStr);
                    //接入规程数据包
                    var cc = await GetopTaskOutDto(inportQShootingRangeBops, FilePath);
                    if (cc.code == 0)
                    {
                        //    System.IO.File.Delete(ZipPath);
                        resultMessage.code = 0;
                        resultMessage.Message = jsonName + "上传成功!";
                        return resultMessage;
                    }
                    else
                    {
                        resultMessage.code = 1;
                        resultMessage.Message = cc.Message;
                        return resultMessage;

                    }
                    //获取传入文件的md5值
                    //var md = GetMD5HashFromFile(filePath);
                    ////判断上传的文件的md5是否相同
                    //if (md == md5)
                    //{
                    //    //获得当前文件夹名称





                    //}
                    //else
                    //{
                    //    resultMessage.code = 1;
                    //    resultMessage.Message = "Md5值不符,请重新上传";
                    //    return resultMessage;

                    //}

                }
                else
                {
                    resultMessage.code = 1;
                    resultMessage.Message = "文件不能为空";
                    return resultMessage;
                }
            }
            catch (Exception ex)
            {
                ConfigHelper.CreateLogText(ex.ToString());
            }
            return resultMessage;


        }
        private bool ZipOpen(string zipPath, string filePath, bool v)
        {
            try
            {
                StaticOperation.UnZip(zipPath, filePath, null, true);
                return true;
            }
            catch
            {
                return false;
            }
        }
        //[Microsoft.AspNetCore.Mvc.DisableRequestSizeLimit]
        //public async Task<ResultMessage> ShootingRangeBop(IFormFile file)
        //{
        //    ResultMessage resultMessage = new ResultMessage();
        //    string uniqueFileName = null;

        //    if (file != null)
        //    {
        //        string[] formatArray = { ".zip", ".7z" };
        //        //文件格式
        //        var fileExtension = Path.GetExtension(file.FileName);
        //        if (!formatArray.Contains(fileExtension))
        //        {

        //            resultMessage.code = 1;
        //            resultMessage.Message = "上传文件格式错误!";
        //            return resultMessage;

        //        }
        //        //文件名称
        //        var jsonName = file.FileName.Split('.')[0];
        //        if (!jsonName.Contains("_shootBop"))
        //        {
        //            resultMessage.code = 1;
        //            resultMessage.Message = "上传文件不合法！";
        //            return resultMessage;
        //        }
        //        //读取文件保存的根目录
        //        string fileSaveRootDir = ConfigHelper.GetAppSetting("App", "ShootingRangePath");

        //        //文件保存的路径(应用的工作目录+文件夹相对路径);
        //        string fileSavePath = Environment.CurrentDirectory + "/wwwroot/" + fileSaveRootDir;
        //        if (!Directory.Exists(fileSavePath))
        //        {
        //            Directory.CreateDirectory(fileSavePath);
        //        }
        //        uniqueFileName = jsonName + fileExtension;
        //        string filePath = Path.Combine(fileSavePath, uniqueFileName);
        //        using (var fileStream = new FileStream(filePath, FileMode.Create))
        //        {
        //            file.CopyTo(fileStream);
        //            fileStream.Flush();
        //        }

        //        var fileSave = uniqueFileName.Split('.')[0];

        //        String DateStr = System.DateTime.Now.ToString("yyyyMMddHHmm");
        //        if (!Directory.Exists(@fileSavePath + "/" + fileSave + "/" + DateStr))
        //        {
        //            Directory.CreateDirectory(@fileSavePath + "/" + fileSave + "/" + DateStr);
        //        }
        //        string destinationDirectoryName = @fileSavePath + "/" + fileSave + "/" + DateStr;
        //        ZipFile.ExtractToDirectory(@filePath, destinationDirectoryName);

        //        var jsonStr = ReadJson.GetFileJson(destinationDirectoryName + "/" + jsonName + ".json");
        //        var ReturnBopTaskOutDto = JsonConvert.DeserializeObject<InportShootingRangeBop>(jsonStr);
        //        //接入规程数据包
        //        var cc = await GetopTaskOutDto(ReturnBopTaskOutDto, destinationDirectoryName);
        //        if (cc.code == 0)
        //        {
        //            resultMessage.code = 0;
        //            resultMessage.Message = jsonName + "上传成功!";
        //            return resultMessage;
        //        }
        //        else
        //        {
        //            resultMessage.code = 1;
        //            resultMessage.Message = cc.Message;
        //            return resultMessage;

        //        }
        //        //获取传入文件的md5值
        //        //var md = GetMD5HashFromFile(filePath);
        //        ////判断上传的文件的md5是否相同
        //        //if (md == md5)
        //        //{
        //        //    //获得当前文件夹名称





        //        //}
        //        //else
        //        //{
        //        //    resultMessage.code = 1;
        //        //    resultMessage.Message = "Md5值不符,请重新上传";
        //        //    return resultMessage;

        //        //}

        //    }
        //    else
        //    {
        //        resultMessage.code = 1;
        //        resultMessage.Message = "文件不能为空";
        //        return resultMessage;
        //    }
        //}
        //解析数据包
        private async Task<ResultMessage> GetopTaskOutDto(List<InportShootingRangeBop> ReturnBopTaskOutDto, string copyPath)
        {
            ResultMessage resultMessage = new ResultMessage();
            var queryBopDesc = ReturnBopTaskOutDto.FirstOrDefault(t => t.bopDescs != null);
            //根据bopdescid 查desc数据
            var bopDesc = _bopDescRepository.GetAll().Where(d => d.Id == queryBopDesc.bopDescs.First().Id).FirstOrDefault();
            List<string> techniqueNums = new List<string>();
            //判断任务是否存在
            //如果desc不存在
            if (bopDesc == null)
            {
                //校验导出型号的id 和发次id 
                if (queryBopDesc.bopDescs.First().ModelId == Guid.Empty || queryBopDesc.bopDescs.First().LotNoId == Guid.Empty)
                {
                    resultMessage.code = 1;
                    resultMessage.Message = "导出数据型号Id和发次Id没有维护!";
                    return resultMessage;
                }
                //校验字典是否维护 否则新增
                var modelTemp = _sysCodeRepository.GetAll().Where(d => d.Id == queryBopDesc.bopDescs.First().ModelId).FirstOrDefault();
                if (modelTemp == null)
                {
                    var modelParent = _sysCodeRepository.GetAll().Where(d => d.PPtr == Guid.Empty && d.CodeId == "型号").FirstOrDefault();
                    if (modelParent == null)
                    {
                        resultMessage.code = 1;
                        resultMessage.Message = "型号数据字典没有创建！";
                        return resultMessage;
                    }
                    else
                    {
                        Sys_Code sys_Code = new Sys_Code();
                        sys_Code.Id = queryBopDesc.bopDescs.First().ModelId.Value;
                        sys_Code.CodeId = "型号";
                        sys_Code.PPtr = modelParent.Id;
                        sys_Code.IsUsed = 1;
                        sys_Code.Description = queryBopDesc.bopDescs.First().Model;
                        //sys_Code.Description = bopDesc.Model;
                        sys_Code.System = true;
                        await _sysCodeRepository.InsertAsync(sys_Code);

                    }
                }
                //校验字典发次id是否维护 否则新增
                var lotNoTemp = _sysCodeRepository.GetAll().Where(d => d.Id == queryBopDesc.bopDescs.First().LotNoId).FirstOrDefault();
                if (lotNoTemp == null)
                {
                    var lotNoParent = _sysCodeRepository.GetAll().Where(d => d.PPtr == Guid.Empty && d.CodeId == "发次").FirstOrDefault();
                    if (lotNoParent == null)
                    {
                        resultMessage.code = 1;
                        resultMessage.Message = "发次数据字典没有创建！";
                        return resultMessage;
                    }
                    else
                    {
                        Sys_Code sys_Code = new Sys_Code();
                        sys_Code.Id = queryBopDesc.bopDescs.First().LotNoId.Value;
                        sys_Code.CodeId = "发次";
                        sys_Code.PPtr = lotNoParent.Id;
                        sys_Code.IsUsed = 1;
                        sys_Code.Description = queryBopDesc.bopDescs.First().LotNo;
                        //sys_Code.Description = bopDesc.LotNo;
                        sys_Code.System = true;
                        await _sysCodeRepository.InsertAsync(sys_Code);
                    }
                }
                //取集合中bopdesc第一条数据
                var tempBopdesc = queryBopDesc.bopDescs.First();
                //插入
                await _bopDescRepository.InsertAsync(tempBopdesc);
                //插入完成去除集合中对应的 bopdesc
                //int cerid = ReturnBopTaskOutDto.FindIndex(x => x.bopDescs != null);
                //ReturnBopTaskOutDto.RemoveAt(cerid);
                //循环剩下的规程数据
                foreach (var data in ReturnBopTaskOutDto)
                {
                    if (data.techniqueEntities.Count > 0)
                    {
                        //获取规程
                        foreach (var item in data.techniqueEntities)
                        {
                            techniqueNums.Add(item.TechniqueNumber);
                            await _techniqueEntityRepository.InsertAsync(item);
                        }

                    }
                    //获取指定表
                    if (data.loadPieceEntities.Count > 0)
                    {
                        foreach (var item in data.loadPieceEntities)
                        {
                            await _loadPieceRepository.InsertAsync(item);
                        }

                    }
                    if (data.makeResourcesEntities.Count > 0)
                    {

                        foreach (var item in data.makeResourcesEntities)
                        {
                            await _makeResourcesEntityRepository.InsertAsync(item);
                        }
                    }
                    if (data.videoEntities.Count > 0)
                    {
                        foreach (var item in data.videoEntities)
                        {
                            await _videoEntityRepository.InsertAsync(item);
                        }
                    }
                    //获取动态表
                    if (data.tableBases.Count > 0)
                    {
                        foreach (var item in data.tableBases)
                        {
                            ConvertFormBase cFormbase = new ConvertFormBase(item.Id, item.FormName, item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort, item.Deptment,
                              item.ParentProductNum, item.ParentProductNum_DisplayName,
                              item.ParentProductNum_Enable, item.ParentProductNum_Show, item.ParentProductNum_Property, item.ParentProductName, item.ParentProductName_DisplayName, item.ParentProductName_Enable, item.ParentProductName_Show,
                              item.ParentProductName_Property, item.FisrtDrawingNum, item.FisrtDrawingNum_DisplayName, item.FisrtDrawingNum_Enable, item.FisrtDrawingNum_Show, item.FisrtDrawingNum_Property,
                              item.FirstDrawingName, item.FirstDrawingName_DisplayName, item.FirstDrawingName_Enable, item.FirstDrawingName_Show, item.FirstDrawingName_Property,
                              item.SecondDrawingNum, item.SecondDrawingNum_DisplayName, item.SecondDrawingNum_Enable, item.SecondDrawingNum_Show, item.SecondDrawingNum_Property,
                              item.SecondDrawingName, item.SecondDrawingName_DisplayName, item.SecondDrawingName_Enable, item.SecondDrawingName_Show, item.SecondDrawingName_Property,
                              item.ProductNum, item.ProductNum_DisplayName, item.ProductNum_Enable, item.ProductNum_Show, item.ProductNum_Property,
                              item.Model, item.Model_DisplayName, item.Model_Enable, item.Model_Show, item.Model_Property, item.RecordElement, item.RecordElement_DisplayName, item.RecordElement_Enable,
                              item.RecordElement_Show, item.RecordElement_Property, item.RecordItem, item.RecordItem_DisplayName, item.RecordItem_Enable, item.RecordItem_Show, item.RecordItem_Property,
                              item.ToolUsed, item.ToolUsed_DisplayName, item.ToolUsed_Enable, item.ToolUsed_Show, item.ToolUsed_Property, item.AbnormalRecord, item.AbnormalRecord_DisplayName,
                              item.AbnormalRecord_Enable, item.AbnormalRecord_Show, item.AbnormalRecord_Property, item.Certificate, item.Certificate_DisplayName, item.Certificate_Enable,
                              item.Certificate_Show, item.Certificate_Property, item.SecondToolUsed, item.SecondToolUsed_DisplayName, item.SecondToolUsed_Enable, item.SecondToolUsed_Show,
                              item.SecondToolUsed_Property, item.ThirdToolUsed, item.ThirdToolUsed_DisplayName, item.ThirdToolUsed_Enable, item.ThirdToolUsed_Show, item.ThirdToolUsed_Property,
                              item.ParamCode, item.ParamCode_DisplayName, item.ParamCode_Enable, item.ParamCode_Show, item.ParamCode_Property

                            );
                            if (item.InspectionSignature != null)
                            {
                                InspectionSignatureEntity inspection = new InspectionSignatureEntity(item.InspectionSignature.InspectionSignatureName, item.InspectionSignature.FirstOperator, item.InspectionSignature.FirstOperator_DisplayName, item.InspectionSignature.FirstOperator_Enable, item.InspectionSignature.FirstOperator_Show, item.InspectionSignature.FirstOperator_Property, item.InspectionSignature.FirstOperatorData, item.InspectionSignature.FirstOperatorData_DisplayName, item.InspectionSignature.FirstOperatorData_Enable, item.InspectionSignature.FirstOperatorData_Show, item.InspectionSignature.FirstOperatorData_Property, item.InspectionSignature.SecondOperator, item.InspectionSignature.SecondOperator_DisplayName, item.InspectionSignature.SecondOperator_Enable, item.InspectionSignature.SecondOperator_Show, item.InspectionSignature.SecondOperator_Property, item.InspectionSignature.SecondOperatorData, item.InspectionSignature.SecondOperatorData_DisplayName, item.InspectionSignature.SecondOperatorData_Enable, item.InspectionSignature.SecondOperatorData_Show, item.InspectionSignature.SecondOperatorData_Property, item.InspectionSignature.ThirdOperator, item.InspectionSignature.ThirdOperator_DisplayName, item.InspectionSignature.ThirdOperator_Enable, item.InspectionSignature.ThirdOperator_Show, item.InspectionSignature.ThirdOperator_Property, item.InspectionSignature.ThirdOperatorData, item.InspectionSignature.ThirdOperatorData_DisplayName, item.InspectionSignature.ThirdOperatorData_Enable, item.InspectionSignature.ThirdOperatorData_Show, item.InspectionSignature.ThirdOperatorData_Property, item.InspectionSignature.FourthOperator, item.InspectionSignature.FourthOperator_DisplayName, item.InspectionSignature.FourthOperator_Enable, item.InspectionSignature.FourthOperator_Show, item.InspectionSignature.FourthOperator_Property, item.InspectionSignature.FourthOperatorData, item.InspectionSignature.FourthOperatorData_DisplayName, item.InspectionSignature.FourthOperatorData_Enable, item.InspectionSignature.FourthOperatorData_Show, item.InspectionSignature.FourthOperatorData_Property, item.InspectionSignature.FifthOperator, item.InspectionSignature.FifthOperator_DisplayName, item.InspectionSignature.FifthOperator_Enable, item.InspectionSignature.FifthOperator_Show, item.InspectionSignature.FifthOperator_Property, item.InspectionSignature.FifthOperatorData, item.InspectionSignature.FifthOperatorData_DisplayName, item.InspectionSignature.FifthOperatorData_Enable, item.InspectionSignature.FifthOperatorData_Show, item.InspectionSignature.FifthOperatorData_Property);
                                cFormbase.InspectionSignature = cFormbase.SetInspectionSignature(inspection);
                            }
                            if (item.RecordRequirements != null)
                            {
                                RecordRequirementsEntity recordRequirements = new RecordRequirementsEntity(item.RecordRequirements.RecordLocation, item.RecordRequirements.RecordLocation_DisplayName, item.RecordRequirements.RecordLocation_Enable, item.RecordRequirements.RecordLocation_Show, item.RecordRequirements.RecordLocation_Property, item.RecordRequirements.RecordStatus, item.RecordRequirements.RecordStatus_DisplayName, item.RecordRequirements.RecordStatus_Enable, item.RecordRequirements.RecordStatus_Show, item.RecordRequirements.RecordStatus_Property, item.RecordRequirements.RecordRequire, item.RecordRequirements.RecordRequire_DisplayName, item.RecordRequirements.RecordRequire_Enable, item.RecordRequirements.RecordRequire_Show, item.RecordRequirements.RecordRequire_Property, item.RecordRequirements.RecordMainopoint, item.RecordRequirements.RecordMainopoint_DisplayName, item.RecordRequirements.RecordMainopoint_Enable, item.RecordRequirements.RecordMainopoint_Show, item.RecordRequirements.RecordMainopoint_Property, item.RecordRequirements.DesignerDemand, item.RecordRequirements.DesignerDemand_DisplayName, item.RecordRequirements.DesignerDemand_Enable, item.RecordRequirements.DesignerDemand_Show, item.RecordRequirements.DesignerDemand_Property, item.RecordRequirements.ProcessorDemand, item.RecordRequirements.ProcessorDemand_DisplayName, item.RecordRequirements.ProcessorDemand_Enable, item.RecordRequirements.ProcessorDemand_Show, item.RecordRequirements.ProcessorDemand_Property, item.RecordRequirements.Remarks, item.RecordRequirements.Remarks_DisplayName, item.RecordRequirements.Remarks_Enable, item.RecordRequirements.Remarks_Show, item.RecordRequirements.Remarks_Property);
                                cFormbase.RecordRequirements = cFormbase.SetRecordRequirements(recordRequirements);
                            }
                            if (item.MultiMedia != null)
                            {
                                MultiMediaEntity multiMedia = new MultiMediaEntity(item.MultiMedia.PhotoNo, item.MultiMedia.PhotoNo_DisplayName, item.MultiMedia.PhotoNo_Enable, item.MultiMedia.PhotoNo_Show, item.MultiMedia.PhotoNo_Property, item.MultiMedia.SecondPhotoNo, item.MultiMedia.SecondPhotoNo_DisplayName, item.MultiMedia.SecondPhotoNo_Enable, item.MultiMedia.SecondPhotoNo_Show, item.MultiMedia.SecondPhotoNo_Property, item.MultiMedia.ThirdPhotoNo, item.MultiMedia.ThirdPhotoNo_DisplayName, item.MultiMedia.ThirdPhotoNo_Enable, item.MultiMedia.ThirdPhotoNo_Show, item.MultiMedia.ThirdPhotoNo_Property, item.MultiMedia.FourthPhotoNo, item.MultiMedia.FourthPhotoNo_DisplayName, item.MultiMedia.FourthPhotoNo_Enable, item.MultiMedia.FourthPhotoNo_Show, item.MultiMedia.FourthPhotoNo_Property);
                                cFormbase.MultiMedia = cFormbase.SetMultiMedia(multiMedia);
                            }
                            if (item.MeasuredResult != null)
                            {
                                MeasuredResultEntity measuredResult = new MeasuredResultEntity(item.MeasuredResult.FirstMeasuredValues, item.MeasuredResult.FirstMeasuredValues_DisplayName, item.MeasuredResult.FirstMeasuredValues_Enable, item.MeasuredResult.FirstMeasuredValues_Show, item.MeasuredResult.FirstMeasuredValues_Property, item.MeasuredResult.SecondMeasuredValues, item.MeasuredResult.SecondMeasuredValues_DisplayName, item.MeasuredResult.SecondMeasuredValues_Enable, item.MeasuredResult.SecondMeasuredValues_Show, item.MeasuredResult.SecondMeasuredValues_Property, item.MeasuredResult.ThirdMeasuredValues, item.MeasuredResult.ThirdMeasuredValues_DisplayName, item.MeasuredResult.ThirdMeasuredValues_Enable, item.MeasuredResult.ThirdMeasuredValues_Show, item.MeasuredResult.ThirdMeasuredValues_Property, item.MeasuredResult.FourthMeasuredValues, item.MeasuredResult.FourthMeasuredValues_DisplayName, item.MeasuredResult.FourthMeasuredValues_Enable, item.MeasuredResult.FourthMeasuredValues_Show, item.MeasuredResult.FourthMeasuredValues_Property, item.MeasuredResult.FirstConfirmResult, item.MeasuredResult.FirstConfirmResult_DisplayName, item.MeasuredResult.FirstConfirmResult_Enable, item.MeasuredResult.FirstConfirmResult_Show, item.MeasuredResult.FirstConfirmResult_Property, item.MeasuredResult.SecondConfirmResult, item.MeasuredResult.SecondConfirmResult_DisplayName, item.MeasuredResult.SecondConfirmResult_Enable, item.MeasuredResult.SecondConfirmResult_Show, item.MeasuredResult.SecondConfirmResult_Property, item.MeasuredResult.ThirdConfirmResult, item.MeasuredResult.ThirdConfirmResult_DisplayName, item.MeasuredResult.ThirdConfirmResult_Enable, item.MeasuredResult.ThirdConfirmResult_Show, item.MeasuredResult.ThirdConfirmResult_Property, item.MeasuredResult.MeasuredActual, item.MeasuredResult.MeasuredActual_DisplayName, item.MeasuredResult.MeasuredActual_Enable, item.MeasuredResult.MeasuredActual_Show, item.MeasuredResult.MeasuredActual_Property);
                                cFormbase.MeasuredResult = cFormbase.SetMeasuredResult(measuredResult);
                            }
                            if (item.Environment != null)
                            {
                                EnvironmentEntity environment = new EnvironmentEntity(item.Environment.Temperature, item.Environment.Temperature_DisplayName, item.Environment.Temperature_Enable, item.Environment.Temperature_Show, item.Environment.Temperature_Property, item.Environment.Humidity, item.Environment.Humidity_DisplayName, item.Environment.Humidity_Enable, item.Environment.Humidity_Show, item.Environment.Humidity_Property, item.Environment.AtmPressure, item.Environment.AtmPressure_DisplayName, item.Environment.AtmPressure_Enable, item.Environment.AtmPressure_Show, item.Environment.AtmPressure_Property);
                                cFormbase.Environment = cFormbase.SetEnvironment(environment);
                            }
                            await _convertFormBaseEntity.InsertAsync(cFormbase);
                        }
                    }
                    //获取路线信息
                    if (data.processLines.Count > 0)
                    {
                        foreach (var item in data.processLines)
                        {
                            await _processLineRepository.InsertAsync(item);
                        }
                    }
                }


            }
            else
            {
                //根据bopdescid 获取表中原始数据
                var bopNodes = _bopNodeRepository.GetAll().Where(d => d.BopDescId == bopDesc.Id).ToList();
                var exportBopNodeIds = queryBopDesc.bopDescs.First().BopNodes.Select(d => d.Id);
                var bopNodeIds = bopNodes.Select(d => d.Id);
                //进行比对更新
                var updateList = exportBopNodeIds.Intersect(bopNodeIds).ToList();
                //进行比对添加
                var addList = exportBopNodeIds.Except(bopNodeIds).ToList();
                //比对删除
                var deleteList = bopNodeIds.Except(exportBopNodeIds).ToList();
                for (int i = 0; i < updateList.Count; i++)
                {
                    var currentNode = bopNodes.Find(d => d.Id == updateList[i]);
                    var exportNode = queryBopDesc.bopDescs.First().BopNodes.First(d => d.Id == updateList[i]);
                    currentNode.ParentId = exportNode.ParentId;
                    currentNode.NodeDrawingNo = exportNode.NodeDrawingNo;
                    currentNode.NodeName = exportNode.NodeName;
                    currentNode.NodeType = exportNode.NodeType;
                    currentNode.Sort = exportNode.Sort;
                    currentNode.NodeLevel = exportNode.NodeLevel;
                    currentNode.ProcessCode = exportNode.ProcessCode;
                    currentNode.IsLeaf = exportNode.IsLeaf;
                    currentNode.ParentCode = exportNode.ParentCode;
                    currentNode.NodeCode = exportNode.NodeCode;
                    currentNode.IsExport = exportNode.IsExport;
                    if (currentNode.TechniqueEntityId == null)
                    {
                        currentNode.BopExprot = exportNode.BopExprot;
                        currentNode.PlanExprot = exportNode.PlanExprot;
                        currentNode.PlanExprot = exportNode.PlanExprot;
                        currentNode.PadId = exportNode.PadId;
                        currentNode.PadName = exportNode.PadName;
                        currentNode.TechniqueEntityId = exportNode.TechniqueEntityId;
                        currentNode.IsReturn = exportNode.IsReturn;
                        currentNode.RelationDate = exportNode.RelationDate;
                        currentNode.ExportDate = exportNode.ExportDate;
                        currentNode.ReturnDate = exportNode.ReturnDate;
                    }
                    currentNode.Loc = exportNode.Loc;
                    currentNode.Details = exportNode.Details;
                    currentNode.Figure = exportNode.Figure;
                    currentNode.Color = exportNode.Color;
                    currentNode.Size = exportNode.Size;
                    currentNode.Fill = exportNode.Fill;
                    currentNode.WorkingHour = exportNode.WorkingHour;
                    currentNode.StartTime = exportNode.StartTime;
                    currentNode.EndTime = exportNode.EndTime;
                    currentNode.AssortState = exportNode.AssortState;
                    currentNode.BopContents = null;
                    await _bopNodeRepository.UpdateAsync(currentNode);
                }
                List<BopNode> bopNodesAdd = new List<BopNode>();
                for (int i = 0; i < addList.Count; i++)
                {
                    var exportNode = queryBopDesc.bopDescs.First().BopNodes.First(d => d.Id == addList[i]);
                    bopNodesAdd.Add(exportNode);
                }
                await _bopNodeRepository.GetDbContext().BulkInsertAsync(bopNodesAdd);
                List<BopNode> bopNodesDele = new List<BopNode>();
                for (int i = 0; i < deleteList.Count; i++)
                {
                    var currentNode = bopNodes.Find(d => d.Id == deleteList[i]);

                    bopNodesDele.Add(currentNode);
                    //await _bopNodeRepository.DeleteAsync(currentNode);
                }
                await _bopNodeRepository.GetDbContext().BulkDeleteAsync(bopNodesDele);
                //比对完成之后 移除desc
                //插入完成去除集合中对应的 bopdesc
                //int cerid = ReturnBopTaskOutDto.FindIndex(x => x.bopDescs != null);
                //ReturnBopTaskOutDto.RemoveAt(cerid);

                //找出desc下所有的规程id
                var techIds = (from cc in _bopNodeRepository.GetAll()
                               join mm in _techniqueEntityRepository.GetAll() on cc.TechniqueEntityId equals mm.Id
                               where cc.BopDescId == bopDesc.Id
                               select mm.Id).ToList();
                //循环 进行更新
                foreach (var data in ReturnBopTaskOutDto)
                {
                    if (data.techniqueEntities.Count > 0)
                    {
                        //循环传入的规程 
                        foreach (var item in data.techniqueEntities)
                        {
                            techniqueNums.Add(item.TechniqueNumber);
                            //与原id进行匹配
                            if (techIds.FindIndex(d => d == item.Id) == -1)
                            {
                                List<Guid> workIds = new List<Guid>();
                                await _techniqueEntityRepository.InsertAsync(item);
                                foreach (var ff in item.ProcessesEntities)
                                {
                                    workIds.AddRange(ff.WorkStepEntities.Select(d => d.Id));
                                }
                                if (workIds.Count > 0)
                                {
                                    if (data.loadPieceEntities.Count > 0)
                                    {
                                        var dataTmep = from cc in data.loadPieceEntities
                                                       join mm in workIds on cc.WorkStepEntityId equals mm
                                                       select cc;

                                        foreach (var ditem in dataTmep)
                                        {
                                            await _loadPieceRepository.InsertAsync(ditem);
                                        }

                                    }
                                    if (data.makeResourcesEntities.Count > 0)
                                    {
                                        var dataTmep = from cc in data.makeResourcesEntities
                                                       join mm in workIds on cc.WorkStepEntityId equals mm
                                                       select cc;

                                        foreach (var ditem in dataTmep)
                                        {
                                            await _makeResourcesEntityRepository.InsertAsync(ditem);
                                        }
                                    }
                                    if (data.videoEntities.Count > 0)
                                    {
                                        var dataTmep = from cc in data.videoEntities
                                                       join mm in workIds on cc.WorkStepEntityId equals mm
                                                       select cc;
                                        foreach (var ditem in dataTmep)
                                        {
                                            await _videoEntityRepository.InsertAsync(ditem);
                                        }
                                    }
                                    if (data.tableBases.Count > 0)
                                    {
                                        var dataTmep = from cc in data.tableBases
                                                       join mm in workIds on cc.WorkStepEntityId equals mm
                                                       select cc;
                                        foreach (var ditem in dataTmep)
                                        {
                                            ConvertFormBase cFormbase = new ConvertFormBase(ditem.Id, ditem.FormName, ditem.SerialNum, ditem.WorkStepEntityId, ditem.ProcessesEntityId, ditem.Sort, ditem.Deptment,
                                              ditem.ParentProductNum, ditem.ParentProductNum_DisplayName,
                                              ditem.ParentProductNum_Enable, ditem.ParentProductNum_Show, ditem.ParentProductNum_Property, ditem.ParentProductName, ditem.ParentProductName_DisplayName, ditem.ParentProductName_Enable, ditem.ParentProductName_Show,
                                              ditem.ParentProductName_Property, ditem.FisrtDrawingNum, ditem.FisrtDrawingNum_DisplayName, ditem.FisrtDrawingNum_Enable, ditem.FisrtDrawingNum_Show, ditem.FisrtDrawingNum_Property,
                                              ditem.FirstDrawingName, ditem.FirstDrawingName_DisplayName, ditem.FirstDrawingName_Enable, ditem.FirstDrawingName_Show, ditem.FirstDrawingName_Property,
                                              ditem.SecondDrawingNum, ditem.SecondDrawingNum_DisplayName, ditem.SecondDrawingNum_Enable, ditem.SecondDrawingNum_Show, ditem.SecondDrawingNum_Property,
                                              ditem.SecondDrawingName, ditem.SecondDrawingName_DisplayName, ditem.SecondDrawingName_Enable, ditem.SecondDrawingName_Show, ditem.SecondDrawingName_Property,
                                              ditem.ProductNum, ditem.ProductNum_DisplayName, ditem.ProductNum_Enable, ditem.ProductNum_Show, ditem.ProductNum_Property,
                                              ditem.Model, ditem.Model_DisplayName, ditem.Model_Enable, ditem.Model_Show, ditem.Model_Property, ditem.RecordElement, ditem.RecordElement_DisplayName, ditem.RecordElement_Enable,
                                              ditem.RecordElement_Show, ditem.RecordElement_Property, ditem.RecordItem, ditem.RecordItem_DisplayName, ditem.RecordItem_Enable, ditem.RecordItem_Show, ditem.RecordItem_Property,
                                              ditem.ToolUsed, ditem.ToolUsed_DisplayName, ditem.ToolUsed_Enable, ditem.ToolUsed_Show, ditem.ToolUsed_Property, ditem.AbnormalRecord, ditem.AbnormalRecord_DisplayName,
                                              ditem.AbnormalRecord_Enable, ditem.AbnormalRecord_Show, ditem.AbnormalRecord_Property, ditem.Certificate, ditem.Certificate_DisplayName, ditem.Certificate_Enable,
                                              ditem.Certificate_Show, ditem.Certificate_Property, ditem.SecondToolUsed, ditem.SecondToolUsed_DisplayName, ditem.SecondToolUsed_Enable, ditem.SecondToolUsed_Show,
                                              ditem.SecondToolUsed_Property, ditem.ThirdToolUsed, ditem.ThirdToolUsed_DisplayName, ditem.ThirdToolUsed_Enable, ditem.ThirdToolUsed_Show, ditem.ThirdToolUsed_Property,
                                              ditem.ParamCode, ditem.ParamCode_DisplayName, ditem.ParamCode_Enable, ditem.ParamCode_Show, ditem.ParamCode_Property

                                            );
                                            if (ditem.InspectionSignature != null)
                                            {
                                                InspectionSignatureEntity inspection = new InspectionSignatureEntity(ditem.InspectionSignature.InspectionSignatureName, ditem.InspectionSignature.FirstOperator, ditem.InspectionSignature.FirstOperator_DisplayName, ditem.InspectionSignature.FirstOperator_Enable, ditem.InspectionSignature.FirstOperator_Show, ditem.InspectionSignature.FirstOperator_Property, ditem.InspectionSignature.FirstOperatorData, ditem.InspectionSignature.FirstOperatorData_DisplayName, ditem.InspectionSignature.FirstOperatorData_Enable, ditem.InspectionSignature.FirstOperatorData_Show, ditem.InspectionSignature.FirstOperatorData_Property, ditem.InspectionSignature.SecondOperator, ditem.InspectionSignature.SecondOperator_DisplayName, ditem.InspectionSignature.SecondOperator_Enable, ditem.InspectionSignature.SecondOperator_Show, ditem.InspectionSignature.SecondOperator_Property, ditem.InspectionSignature.SecondOperatorData, ditem.InspectionSignature.SecondOperatorData_DisplayName, ditem.InspectionSignature.SecondOperatorData_Enable, ditem.InspectionSignature.SecondOperatorData_Show, ditem.InspectionSignature.SecondOperatorData_Property, ditem.InspectionSignature.ThirdOperator, ditem.InspectionSignature.ThirdOperator_DisplayName, ditem.InspectionSignature.ThirdOperator_Enable, ditem.InspectionSignature.ThirdOperator_Show, ditem.InspectionSignature.ThirdOperator_Property, ditem.InspectionSignature.ThirdOperatorData, ditem.InspectionSignature.ThirdOperatorData_DisplayName, ditem.InspectionSignature.ThirdOperatorData_Enable, ditem.InspectionSignature.ThirdOperatorData_Show, ditem.InspectionSignature.ThirdOperatorData_Property, ditem.InspectionSignature.FourthOperator, ditem.InspectionSignature.FourthOperator_DisplayName, ditem.InspectionSignature.FourthOperator_Enable, ditem.InspectionSignature.FourthOperator_Show, ditem.InspectionSignature.FourthOperator_Property, ditem.InspectionSignature.FourthOperatorData, ditem.InspectionSignature.FourthOperatorData_DisplayName, ditem.InspectionSignature.FourthOperatorData_Enable, ditem.InspectionSignature.FourthOperatorData_Show, ditem.InspectionSignature.FourthOperatorData_Property, ditem.InspectionSignature.FifthOperator, ditem.InspectionSignature.FifthOperator_DisplayName, ditem.InspectionSignature.FifthOperator_Enable, ditem.InspectionSignature.FifthOperator_Show, ditem.InspectionSignature.FifthOperator_Property, ditem.InspectionSignature.FifthOperatorData, ditem.InspectionSignature.FifthOperatorData_DisplayName, ditem.InspectionSignature.FifthOperatorData_Enable, ditem.InspectionSignature.FifthOperatorData_Show, ditem.InspectionSignature.FifthOperatorData_Property);

                                                cFormbase.InspectionSignature = cFormbase.SetInspectionSignature(inspection);
                                            }
                                            if (ditem.RecordRequirements != null)
                                            {
                                                RecordRequirementsEntity recordRequirements = new RecordRequirementsEntity(ditem.RecordRequirements.RecordLocation, ditem.RecordRequirements.RecordLocation_DisplayName, ditem.RecordRequirements.RecordLocation_Enable, ditem.RecordRequirements.RecordLocation_Show, ditem.RecordRequirements.RecordLocation_Property, ditem.RecordRequirements.RecordStatus, ditem.RecordRequirements.RecordStatus_DisplayName, ditem.RecordRequirements.RecordStatus_Enable, ditem.RecordRequirements.RecordStatus_Show, ditem.RecordRequirements.RecordStatus_Property, ditem.RecordRequirements.RecordRequire, ditem.RecordRequirements.RecordRequire_DisplayName, ditem.RecordRequirements.RecordRequire_Enable, ditem.RecordRequirements.RecordRequire_Show, ditem.RecordRequirements.RecordRequire_Property, ditem.RecordRequirements.RecordMainopoint, ditem.RecordRequirements.RecordMainopoint_DisplayName, ditem.RecordRequirements.RecordMainopoint_Enable, ditem.RecordRequirements.RecordMainopoint_Show, ditem.RecordRequirements.RecordMainopoint_Property, ditem.RecordRequirements.DesignerDemand, ditem.RecordRequirements.DesignerDemand_DisplayName, ditem.RecordRequirements.DesignerDemand_Enable, ditem.RecordRequirements.DesignerDemand_Show, ditem.RecordRequirements.DesignerDemand_Property, ditem.RecordRequirements.ProcessorDemand, ditem.RecordRequirements.ProcessorDemand_DisplayName, ditem.RecordRequirements.ProcessorDemand_Enable, ditem.RecordRequirements.ProcessorDemand_Show, ditem.RecordRequirements.ProcessorDemand_Property, ditem.RecordRequirements.Remarks, ditem.RecordRequirements.Remarks_DisplayName, ditem.RecordRequirements.Remarks_Enable, ditem.RecordRequirements.Remarks_Show, ditem.RecordRequirements.Remarks_Property);
                                                cFormbase.RecordRequirements = cFormbase.SetRecordRequirements(recordRequirements);
                                            }
                                            if (ditem.MultiMedia != null)
                                            {
                                                MultiMediaEntity multiMedia = new MultiMediaEntity(ditem.MultiMedia.PhotoNo, ditem.MultiMedia.PhotoNo_DisplayName, ditem.MultiMedia.PhotoNo_Enable, ditem.MultiMedia.PhotoNo_Show, ditem.MultiMedia.PhotoNo_Property, ditem.MultiMedia.SecondPhotoNo, ditem.MultiMedia.SecondPhotoNo_DisplayName, ditem.MultiMedia.SecondPhotoNo_Enable, ditem.MultiMedia.SecondPhotoNo_Show, ditem.MultiMedia.SecondPhotoNo_Property, ditem.MultiMedia.ThirdPhotoNo, ditem.MultiMedia.ThirdPhotoNo_DisplayName, ditem.MultiMedia.ThirdPhotoNo_Enable, ditem.MultiMedia.ThirdPhotoNo_Show, ditem.MultiMedia.ThirdPhotoNo_Property, ditem.MultiMedia.FourthPhotoNo, ditem.MultiMedia.FourthPhotoNo_DisplayName, ditem.MultiMedia.FourthPhotoNo_Enable, ditem.MultiMedia.FourthPhotoNo_Show, ditem.MultiMedia.FourthPhotoNo_Property);
                                                cFormbase.MultiMedia = cFormbase.SetMultiMedia(multiMedia);
                                            }
                                            if (ditem.MeasuredResult != null)
                                            {
                                                MeasuredResultEntity measuredResult = new MeasuredResultEntity(ditem.MeasuredResult.FirstMeasuredValues, ditem.MeasuredResult.FirstMeasuredValues_DisplayName, ditem.MeasuredResult.FirstMeasuredValues_Enable, ditem.MeasuredResult.FirstMeasuredValues_Show, ditem.MeasuredResult.FirstMeasuredValues_Property, ditem.MeasuredResult.SecondMeasuredValues, ditem.MeasuredResult.SecondMeasuredValues_DisplayName, ditem.MeasuredResult.SecondMeasuredValues_Enable, ditem.MeasuredResult.SecondMeasuredValues_Show, ditem.MeasuredResult.SecondMeasuredValues_Property, ditem.MeasuredResult.ThirdMeasuredValues, ditem.MeasuredResult.ThirdMeasuredValues_DisplayName, ditem.MeasuredResult.ThirdMeasuredValues_Enable, ditem.MeasuredResult.ThirdMeasuredValues_Show, ditem.MeasuredResult.ThirdMeasuredValues_Property, ditem.MeasuredResult.FourthMeasuredValues, ditem.MeasuredResult.FourthMeasuredValues_DisplayName, ditem.MeasuredResult.FourthMeasuredValues_Enable, ditem.MeasuredResult.FourthMeasuredValues_Show, ditem.MeasuredResult.FourthMeasuredValues_Property, ditem.MeasuredResult.FirstConfirmResult, ditem.MeasuredResult.FirstConfirmResult_DisplayName, ditem.MeasuredResult.FirstConfirmResult_Enable, ditem.MeasuredResult.FirstConfirmResult_Show, ditem.MeasuredResult.FirstConfirmResult_Property, ditem.MeasuredResult.SecondConfirmResult, ditem.MeasuredResult.SecondConfirmResult_DisplayName, ditem.MeasuredResult.SecondConfirmResult_Enable, ditem.MeasuredResult.SecondConfirmResult_Show, ditem.MeasuredResult.SecondConfirmResult_Property, ditem.MeasuredResult.ThirdConfirmResult, ditem.MeasuredResult.ThirdConfirmResult_DisplayName, ditem.MeasuredResult.ThirdConfirmResult_Enable, ditem.MeasuredResult.ThirdConfirmResult_Show, ditem.MeasuredResult.ThirdConfirmResult_Property, ditem.MeasuredResult.MeasuredActual, ditem.MeasuredResult.MeasuredActual_DisplayName, ditem.MeasuredResult.MeasuredActual_Enable, ditem.MeasuredResult.MeasuredActual_Show, ditem.MeasuredResult.MeasuredActual_Property);
                                                cFormbase.MeasuredResult = cFormbase.SetMeasuredResult(measuredResult);
                                            }
                                            if (ditem.Environment != null)
                                            {
                                                EnvironmentEntity environment = new EnvironmentEntity(ditem.Environment.Temperature, ditem.Environment.Temperature_DisplayName, ditem.Environment.Temperature_Enable, ditem.Environment.Temperature_Show, ditem.Environment.Temperature_Property, ditem.Environment.Humidity, ditem.Environment.Humidity_DisplayName, ditem.Environment.Humidity_Enable, ditem.Environment.Humidity_Show, ditem.Environment.Humidity_Property, ditem.Environment.AtmPressure, ditem.Environment.AtmPressure_DisplayName, ditem.Environment.AtmPressure_Enable, ditem.Environment.AtmPressure_Show, ditem.Environment.AtmPressure_Property);
                                                cFormbase.Environment = cFormbase.SetEnvironment(environment);
                                            }
                                            await _convertFormBaseEntity.InsertAsync(cFormbase);
                                        }
                                    }
                                }
                            }
                        }

                    }
                    //try
                    //{
                    //    if (data.processLines.Count > 0)
                    //    {
                    //        //  var processDesc = _processLineRepository.GetAll().Where(d => d.BopDescId == bopDesc.Id);
                    //        //foreach (var pro in processDesc.ToList())
                    //        //{
                    //        //_processLineRepository.HardDelete(pro);

                    //        // }
                    //        _processLineRepository.GetDbContext().Database.AutoTransactionsEnabled = false;
                    //        _processLineRepository.GetDbContext().Database.CurrentTransaction?.Dispose();
                    //        var tran = _processLineRepository.GetDbContext().Database.BeginTransaction();
                    //        try
                    //        {
                    //            _processLineRepository.GetDbContext().Database.ExecuteSqlCommand("delete from ProcessLines where BopDescId ='" + bopDesc.Id + "'");
                    //            //await _processLineRepository.HardDeleteAsync(d => d.BopDescId == bopDesc.Id);

                    //            var repeatData = (from pro in _processLineRepository.GetAll().ToList()
                    //                              join rop in data.processLines on pro.Id equals rop.Id
                    //                              select pro).ToList();

                    //            foreach (var pro in repeatData)
                    //            {
                    //                _processLineRepository.GetDbContext().Database.ExecuteSqlCommand("delete from ProcessLines where Id ='" + pro.Id + "'");
                    //            }
                    //            tran.Commit();
                    //            //await _processLineRepository.GetDbContext().BulkDeleteAsync(repeatData.ToList());

                    //            await _processLineRepository.GetDbContext().BulkInsertAsync(data.processLines);
                    //            //foreach (var item in ReturnBopTaskOutDto.processLines)
                    //            //{
                    //            //    await _processLineRepository.InsertAsync(item);
                    //            //}
                    //        }
                    //        catch (Exception ex)
                    //        {
                    //            tran.Rollback();
                    //            throw;
                    //        }
                    //    }
                    //}
                    //catch (Exception ex)
                    //{
                    //    throw;
                    //}
                }



            }

            string fileBopRootDir = ConfigHelper.GetAppSetting("App", "DownLoadFileRootPath");
            for (int i = 0; i < techniqueNums.Count; i++)
            {
                string sourcePatch = copyPath + "/" + techniqueNums[i];
                string srcPatch = Environment.CurrentDirectory + "/wwwroot/" + fileBopRootDir + "/" + techniqueNums[i] + "/";
                if (!Directory.Exists(srcPatch))
                {
                    Directory.CreateDirectory(srcPatch);
                   
                }
                bool copyBool = CopyDir(sourcePatch, srcPatch);
                if (!copyBool)
                {
                    throw new UserFriendlyException("拷贝文件失败！");
                }
                    DirectoryInfo root = new DirectoryInfo(sourcePatch);
                    var dics = root.GetDirectories();
                    for (int k = 0; k < dics.Length; k++)
                    {
                        string tempPath = srcPatch + dics[k].Name + "/";

                        if (dics[k].Name == "Exception")
                        {
                            string pathEx = dics[k].FullName + "/picture" + "/";
                            if (Directory.Exists(pathEx))
                            {
                                string exceptionpath = Environment.CurrentDirectory + "/wwwroot/" + "/Inspection/";
                                if (CopyDir(pathEx, exceptionpath))
                                {
                                }
                                else
                                {
                                    throw new UserFriendlyException("拷贝文件失败！");
                                }
                            }
                        }
                        else
                        {
                            if (!Directory.Exists(tempPath))
                            {
                                Directory.CreateDirectory(srcPatch);
                            }
                            if (CopyDir(dics[k].FullName, tempPath))
                            {
                            }
                            else
                            {
                                throw new UserFriendlyException("拷贝文件失败！");
                            }
                        }
                    }
                    //Directory.Delete(srcPatch, true);
                
            }
          //  resultMessage.code = 0;

            resultMessage.code = 0;
            resultMessage.Message = "该型号和发次的包的数据已存在库中,已增量覆盖!";
            return resultMessage;

           // return resultMessage;
        }


        #endregion
        private string GetMD5HashFromFile(string fileName)
        {
            try
            {
                FileStream file = new FileStream(fileName, FileMode.Open);
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] retVal = md5.ComputeHash(file);
                file.Close();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < retVal.Length; i++)
                {
                    sb.Append(retVal[i].ToString("x2"));
                }
                return sb.ToString();
            }
            catch (Exception ex)
            {
                throw new Exception("GetMD5HashFromFile() fail,error:" + ex.Message);
            }
        }
        //压缩数据包
        public static bool CompressMulti(List<string> list, string strZipName, bool isDirStruct)
        {
            if (list == null)
            {
                throw new ArgumentNullException("list");
            }
            if (string.IsNullOrEmpty(strZipName))
            {
                throw new ArgumentNullException(strZipName);
            }
            try
            {
                //设置编码，解决压缩文件时中文乱码
                using (var zip = new Ionic.Zip.ZipFile(Encoding.Default))
                {
                    foreach (var path in list)
                    {
                        //取目录名称
                        var fileName = Path.GetFileName(path);
                        //如果是目录
                        if (Directory.Exists(path))
                        {
                            //按目录结构压缩
                            if (isDirStruct)
                            {
                                zip.AddDirectory(path, fileName);
                            }
                            else
                            {
                                //目录下的文件都压缩到Zip的根目录
                                zip.AddDirectory(path);
                            }
                        }
                        if (File.Exists(path))
                        {
                            zip.AddFile(path);
                        }
                    }

                    zip.UseZip64WhenSaving = Ionic.Zip.Zip64Option.Always;
                    //压缩
                    zip.Save(strZipName);
                    return true;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

    }
}
